[英]MemoryCache and multiple per call WCF services
Is using the MemoryCache
class a valid option if I want the cached data to be visible across multiple WCF services (with PerCall instance mode)? 如果我希望缓存数据在多个WCF服务中可见(使用PerCall实例模式),那么使用
MemoryCache
类是一个有效的选项吗?
There are two cases: 有两种情况:
1.the services are all hosted in the same app in IIS
the answer is yes if you are using MemoryCache.Default
as your default cache object 如果您使用
MemoryCache.Default
作为默认缓存对象,答案是肯定的
From MSDN 来自MSDN
This property always returns a reference to the default cache instance. For typical application scenarios, only one instance of MemoryCache is required.
you could use it like the following 你可以像下面这样使用它
ObjectCache cache = MemoryCache.Default;
Is it possible to configure it in the following way 是否可以按以下方式配置它
<system.runtime.caching>
<memoryCache>
<namedCaches>
<add name="Default" physicalMemoryLimitPercentage="20"/>
</namedCaches>
</memoryCache>
</system.runtime.caching>
from your others services instance you can access your memory cache like the following 从您的其他服务实例,您可以访问您的内存缓存,如下所示
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
this will be a bit tricky but it will remains a valid option you can create a dedicated webservice for caching that can be used by others webservices using the netnamedPipeBinding
given that are on the same server 这将有点棘手但它仍然是一个有效的选项,您可以创建一个专用的Web服务进行缓存,其他webservices可以使用同一服务器上给出的
netnamedPipeBinding
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.