1 缓存使用图示:

缓存使用

2 新增缓存的方法:

 private void AddCacheItem(string rawKey, object value)
    {
        System.Web.Caching.Cache DataCache = HttpRuntime.Cache;

        // Make sure MasterCacheKeyArray[0] is in the cache - if not, add it
        if (DataCache[MasterCacheKeyArray[0]] == null)
            DataCache[MasterCacheKeyArray[0]] = DateTime.Now;

        // Add a CacheDependency
        System.Web.Caching.CacheDependency dependency = 
            new System.Web.Caching.CacheDependency(null, MasterCacheKeyArray);
        DataCache.Insert(
            GetCacheKey(rawKey), //名称
            value, dependency,//value是要放在缓存中的对象
            DateTime.Now.AddSeconds(CacheDuration),//设置对象在缓存中的到期时间
            System.Web.Caching.Cache.NoSlidingExpiration);
    }
 

相关文章: