基于CacheManager组件的缓存产品配置

一、Couchbase

使用CacheManager组件,在配置Couchbase缓存支持时,由于对配置节cache handle命名规则要求不了解,费了点时间查了源码才明白。

section配置节

    <sectionGroup name="couchbaseClients">
      <section name="couchbase" type="Couchbase.Configuration.Client.Providers.CouchbaseClientSection, Couchbase.NetClient" />
    </sectionGroup>

cacheManager中的cache节点配置

    <managers>
      <cache name="cacheName" updateMode="Up" enableStatistics="false" enablePerformanceCounters="false">        
        <handle name="couchbaseClients/couchbase:default" ref="couchbaseHandle" expirationMode="Absolute" timeout="50s"/>
      </cache>
    </managers>
注意:

handleName的命名规则必须满足可通过配置名称找到CouchbaseClientSection对应配置节,即couchbaseClients下的couchbase

Bucket名为可选,默认为default

格式为<configKey>:<bucketName>

源码参考CacheManager.Couchbase.BucketCacheHandle

            // we can configure the bucket name by having "<configKey>:<bucketName>" as handle's
            // name value
            var nameParts = configuration.Key.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
            Ensure(nameParts.Length > 0, "Handle key is not valid {0}", configuration.Key);

            this.configurationName = nameParts[0];

            if (nameParts.Length == 2)
            {
                this.bucketName = nameParts[1];
            }

            this.configuration = CouchbaseConfigurationManager.GetConfiguration(this.configurationName);
            this.bucketConfiguration = CouchbaseConfigurationManager.GetBucketConfiguration(this.configuration, this.bucketName);
            this.bucket = CouchbaseConfigurationManager.GetBucket(this.configuration, this.configurationName, this.bucketName);

二、memcached

memcached配置时,对cacheManager中的cache节点handle的命名也和Couchbase类型,配置如下

    <sectionGroup name="enyim.com">
      <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
    </sectionGroup>
    <managers>
      <cache name="cacheName" updateMode="Up" enableStatistics="false" enablePerformanceCounters="false">        
        <handle name="enyim.com/memcached" ref="memcachedHandle"/>
      </cache> 
    </managers>

或者

    <managers>
      <cache name="cacheName" updateMode="Up" enableStatistics="false" enablePerformanceCounters="false">        
        <handle name="default" ref="memcachedHandle"/>
      </cache> 
    </managers>
handle命名为 enyim.com/memcacheddefault,default时组件自动为转化为enyim.com/memcached

转载于:https://www.cnblogs.com/shijun/p/5287625.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值