Liv*_* M. 4 c# iis wcf caching memorycache
MemoryCache如果我希望缓存数据在多个WCF服务中可见(使用PerCall实例模式),那么使用该类是一个有效的选项吗?
有两种情况:
1.the services are all hosted in the same app in IIS
答案是肯定的,如果你使用的是MemoryCache.Default作为默认的缓存对象
从MSDN
This property always returns a reference to the default cache instance. For typical application scenarios, only one instance of MemoryCache is required.
你可以像下面这样使用它
ObjectCache cache = MemoryCache.Default;
Run Code Online (Sandbox Code Playgroud)
是否可以按以下方式配置它
<system.runtime.caching>
<memoryCache>
<namedCaches>
<add name="Default" physicalMemoryLimitPercentage="20"/>
</namedCaches>
</memoryCache>
</system.runtime.caching>
Run Code Online (Sandbox Code Playgroud)
从您的其他服务实例,您可以访问您的内存缓存,如下所示
List<string> cacheKeys = MemoryCache.Default.Select(kvp => kvp.Key).ToList();
foreach (string cacheKey in cacheKeys)
MemoryCache.Default.Remove(cacheKey);
Run Code Online (Sandbox Code Playgroud)
2.the services are hosted in different IIS applications on the same server
这将有点棘手,但它仍然是一个有效的选项,您可以创建一个专用的Web服务进行缓存,其他Web服务可以使用netnamedPipeBinding同一服务器上的给定
| 归档时间: |
|
| 查看次数: |
3824 次 |
| 最近记录: |