小编use*_*034的帖子

System.Runtime.Cache立即过期

我有一个网页缓存一些查询字符串值30秒,以便它不会收到重复的值.我使用以下课程:

public class MyCache   {

private static ObjectCache cache = MemoryCache.Default;

public MyCache() { }


public void Insert(string key, string value)
{

    CacheItemPolicy policy = new CacheItemPolicy();
    policy.Priority = CacheItemPriority.Default;
    policy.SlidingExpiration = new TimeSpan(0, 0, 30);
    policy.RemovedCallback = new CacheEntryRemovedCallback(this.Cacheremovedcallback);

    cache.Set(key, value, policy);
}

public bool Exists(string key)
{
    return cache.Contains(key);
}

public void Remove(string key)
{
    cache.Remove(key);
}

private void Cacheremovedcallback(CacheEntryRemovedArguments arguments)
{      
    FileLog.LogToFile("Cache item removed. Reason: " + arguments.RemovedReason.ToString() +  "; Item: [" +  arguments.CacheItem.Key + ", " …
Run Code Online (Sandbox Code Playgroud)

.net c# caching

5
推荐指数
1
解决办法
3737
查看次数

标签 统计

.net ×1

c# ×1

caching ×1