[学习笔记]Senparc.CO2NET 缓存使用笔记

>笔记1:如果需要调用远程的Redis,那么您需要2步

  步骤1:

  在项目的web.config文件中配置

    <!-- Cache.Redis连接配置 -->
    <add key="Cache_Redis_Configuration" value="127.0.0.1:6379" />

     <!--Cache.Redis连接配置--> 
    <add key="Cache_Memcached_Configuration" value="Memcached配置" />

  步骤2:

 1 //先注册Redis配置,不立即启用(add)
 2 Register.SetConfigurationOption(ConfigHelper.AppSettings("Cache_Redis_Configuration"));
 3 
 4 //如需立即改用某种缓存策略,只需要这样做(注意:是全局立即生效):
 5 CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisObjectCacheStrategy.Instance);
 6 
 7 var cache = CacheStrategyFactory.GetObjectCacheStrategyInstance();
 8 var count = cache.Get<int>("Hello",true);
 9 count++;
10 cache.Set("Hello", count,null,true);
11 
12 StringBuilder strRes = new StringBuilder();
13 strRes.Append("Hello的值为:" + count.ToString() + ",");
14 strRes.Append("CacheType的值为:" + cache.GetType().ToString());

  然后就可以随便玩儿了.

 

以上亲测,有疑问欢迎关注我的微信公众号进行提问

公众号:sxmljx

 

posted @ 2018-10-31 11:51  MartyZane  阅读(1871)  评论(0编辑  收藏  举报