我使用 EnterpriseLibrary cacheManager
<cacheManagers>
<add name="NonExperimentalAppsCache" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null" expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="10000" numberToRemoveWhenScavenging="100" backingStoreName="Null Storage" />
</cacheManagers>
我希望体验时间为 1 分钟(绝对,在每次缓存触摸时不刷新)我该怎么做?因为现在它可以保存更长时间的数据。
我在缓存上使用存储库
public static List<string> GetAllNonExperimentalAppsNames()
{
List<string> nonExperimentalAppsNames = NonExperimentalAppsCacheManager.Get();
if (nonExperimentalAppsNames == null)
{
//was not found in the cache
nonExperimentalAppsNames = GetAllNonExperimentalAppsNamesFromDb();
if (nonExperimentalAppsNames != null)
{
NonExperimentalAppsCacheManager.Set(nonExperimentalAppsNames);
}
else
{
mApplicationLogger.Info(string.Format("GetAllNonExperimentalAppsNames:: nonExperimentalAppsNames list is null"));
}
}
return nonExperimentalAppsNames;
}
..
internal static class NonExperimentalAppsCacheManager
{
private const string NONEXPERIMENTALAPPS = "NonExperimentalApps";
private static readonly ICacheManager nonExperimentalAppsCache = CacheFactory.GetCacheManager("NonExperimentalAppsCache");
internal static List<String> Get()
{
return nonExperimentalAppsCache[NONEXPERIMENTALAPPS] as List<String>;
}
internal static void Set(List<String> settings)
{
nonExperimentalAppsCache.Add(NONEXPERIMENTALAPPS, settings);
}
}