2 대의 서버에 내 웹 사이트 코드가 있고 그 사이에 공유 캐시가 있어야하므로 Microsoft AppFabric을 사용하고 있습니다. 사이트 방문자 당 하나의 항목이 아니라 한 항목의 합계 만 캐시에 하나의 항목 만 남기고 싶습니다.동일한 키를 사용하여 AppFabric 캐시에 여러 캐시 항목이있는 이유는 무엇입니까?
이 작업을 수행하는 데 사용하는 코드는 아래에 있지만 원하는대로 작동하지 않습니다. 문제는 캐시에 많은 항목이 있다는 것인데, 모두 동일한 키를 가지고 있음에도 불구하고 말입니다. 그러나 그것은 다른 일이 될 수 있습니다. 자세한 내용은 코드 주석을 참조하십시오.
Web.config
에서 :
<dataCacheClient>
<hosts>
<host name="MyHost1" cachePort="22233"/>
<host name="MyHost2" cachePort="22233"/>
</hosts>
<securityProperties mode="None" protectionLevel="None" />
</dataCacheClient>
...
<system.web>
<sessionState mode="InProc" customProvider="AppFabricCacheSessionStoreProvider">
<providers>
<add
name="AppFabricCacheSessionStoreProvider"
type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider"
cacheName="MyCache"
sharedId="MySharedApp"/>
</providers>
</sessionState>
...
</system.web>
Global.asax.cs
에서 :
private static DataCacheFactory _cacheFactory = new DataCacheFactory();
private static DataCache _cache;
private void RegisterCacheEntry(){
try
{
// Set up cache
_cache = _cacheFactory.GetCache("MyCache");
// Prevent duplicate key addition
if (_cache.GetCacheItem(CacheItemKey) != null || _cache.Get(CacheItemKey) != null)
return;
// Add item to cache
_cache.Add(CacheItemKey, CacheItem, TimeSpan.FromMinutes(10));
// When the cache item is removed, the callback:
// 1) sends me an email
// 2) adds the same item with the same key to the cache again.
// So I SHOULD be getting one email every 10 minutes.
// However, it starts with one, but the number of emails that I get increases every 10 minutes.
// i.e., I get one email at time t=0, two emails at t=1, three at t=2, then four, etc.
_cache.AddItemLevelCallback(CacheItemKey, DataCacheOperations.RemoveItem, CacheItemRemovedCallback);
}
catch (Exception e){}
}
당신은 왜, 내가 캐시 제한 시간을 사용하여 Windows 서비스를 시뮬레이션하기 위해 노력하고있어 내가 뭘하고 더 많은 정보를 원한다면 here. 하지만이 두 서버에서 작동하도록 노력하고있어.
전체' 섹션을 삭제했지만 아무 것도 변경하지 않은 것 같습니다. 나는 아직도 여러 항목을 가지고있다. –
Kalina
여러 항목이 있다는 것을 어떻게 아나요? PS cmdlet Get-Statistics를 사용하고 있습니까? – Cybermaxs
난 그냥 여러 캐시 항목이라고 가정했다. PowerShell에 액세스 할 수 없어 확인할 수 없습니다. 그러나 그 밖의 무엇이 문제 일 수 있 었는가? 하나의 캐시 항목이 여러 번 만료됩니까? – Kalina