MemoryCache and several WCF service calls

Does the class use a MemoryCachevalid parameter if I want cached data to be visible in multiple WCF services (with PerCall instance mode )?

There are two cases:

  • all services are hosted in a single application in IIS
  • services are hosted in different IIS applications on the same server
+4
source share
1 answer

1.the services are all hosted in the same app in IIS

the answer is yes, if you use the MemoryCache.Defaultdefault cache object

From MSDN

This property always returns a reference to the default cache instance. For typical application scenarios, only one instance of MemoryCache is required.

You can use it as below.

ObjectCache cache = MemoryCache.Default;

Is it possible to configure it as follows.

<system.runtime.caching>
 <memoryCache>
  <namedCaches>
   <add name="Default" physicalMemoryLimitPercentage="20"/>
  </namedCaches>
 </memoryCache>
</system.runtime.caching>

List<string> cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList();

foreach (string cacheKey in cacheKeys)
          MemoryCache.Default.Remove(cacheKey); 

2.the services are hosted in different IIS applications on the same server

, , - , - netnamedPipeBinding,

+5

Source: https://habr.com/ru/post/1548071/


All Articles