缓存补充:

petshop的缓存中还涉及到一个命名空间TableCacheDependency

该命名空间下有如下类:

Category.cs

Item.cs

Product.cs

TableDependency.cs

即我们要对Category,Item,Product 三个表进行缓存依赖。

首先看类TableDependency

 

using System.Web.Caching;
using System.Configuration;

namespace PetShop.TableCacheDependency {

    /// <summary>
    /// This is the base class for SQL2KCacheDependency implementation that encapsulates common
    /// algorithm to retrieve database and table names from configuration file and create
    /// the necessary AggregateCacheDependency object
    /// </summary>
    public abstract class TableDependency : PetShop.ICacheDependency.IPetShopCacheDependency {

        // This is the separator that's used in web.config
        protected char[] configurationSeparator = new char[] { ',' };

        protected AggregateCacheDependency dependency = new AggregateCacheDependency();

        /// <summary>
        /// The constructor retrieves all related configuration and add CacheDependency object accordingly
        /// </summary>
        /// <param name="configKey">Configuration key for specific derived class implementation</param>
        protected TableDependency(string configKey) {

            string dbName = ConfigurationManager.AppSettings["CacheDatabaseName"];
            string tableConfig = ConfigurationManager.AppSettings[configKey];
            string[] tables = tableConfig.Split(configurationSeparator);

            foreach (string tableName in tables)
                dependency.Add(new SqlCacheDependency(dbName, tableName));
        }

        public AggregateCacheDependency GetDependency() {
            return dependency;
        }
    }
}

 

具体类Product

--------------------

using System.Web.Caching;

namespace PetShop.TableCacheDependency {
    /// <summary>
    /// Implementation of Product Cache Dependency for SQL Server 2000
    /// </summary>
    public class Product : TableDependency {

        /// <summary>
        /// Call its base constructor by passing its specific configuration key
        /// </summary>
        public Product() : base("ProductTableDependency") { }
    }
}

 

对应的web.config文件有:


  <!-- Cache dependency options. Possible values: PetShop.TableCacheDependency for SQL Server and keep empty for ORACLE -->
  <add key="CacheDependencyAssembly" value="PetShop.TableCacheDependency"/>
  <!-- CacheDatabaseName should match the name under caching section, when using TableCacheDependency -->
  <add key="CacheDatabaseName" value="MSPetShop4"/>
  <!-- *TableDependency lists table dependency for each instance separated by comma -->
  <add key="CategoryTableDependency" value="Category"/>
  <add key="ProductTableDependency" value="Product,Category"/>
  <add key="ItemTableDependency" value="Product,Category,Item"/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值