MSPetShop4 TableCacheDependency缓存的用法

来源:互联网 发布:钱多事少离家近 知乎 编辑:程序博客网 时间:2024/06/05 20:07

MSPetShop4 TableCacheDependency缓存的用法


 string key = "product_by_category_" + category;
            IList<ProductInfo> data = (IList<ProductInfo>)HttpRuntime.Cache[key];

            // Check if the data exists in the data cache
            if (data == null) {

                // If the data is not in the cache then fetch the data from the business logic tier
                data = product.GetProductsByCategory(category);

                // Create a AggregateCacheDependency object from the factory
                AggregateCacheDependency cd = DependencyFacade.GetProductDependency();

                // Store the output in the data cache, and Add the necessary AggregateCacheDependency object
                HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(productTimeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            }

是查询结果 data。data查询过程中使用到cd做的缓存表。

写入缓存和相关关联 HttpRuntime.Cache.Add(key, data, cd, DateTime.Now.AddHours(productTimeout), Cache.NoSlidingExpiration, CacheItemPriority.High, null);

类方法说明:
public Object Add ( string key, Object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback)

原创粉丝点击