CacheManager memcached配置 [英] CacheManager memcached configuration

查看:100
本文介绍了CacheManager memcached配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将为.net项目使用 CacheManager .问题是我找不到CacheManager.Memcached用法的任何示例.

I'm going to use CacheManager for my .net project. The problem is that I can't find any examples of CacheManager.Memcached usage.

这是我的用法:

public class GlobalCache
{
     private static ICacheManager<object> memcachedClient { get; set; }

     private static readonly object locker = new object();

     static GlobalCache()
     {
          if (memcachedClient == null)
          {
               lock (locker)
               {
                  memcachedClient = CacheFactory.Build("memcached", settings => settings.WithMemcachedCacheHandle("memcached"));
               }
          }
     }
}

Web.config:

Web.config:

   <configuration>
     <enyim.com>
       <memcached protocol="Binary">
         <servers>
           <add address="127.0.0.1" port="11211" />
         </servers>
       </memcached>
     </enyim.com>

     <cache name="memcached">
        <handle name="memcached"/>
     </cache>
   </configuration>

我的错误是: http://c2n.me/3hSHqvR.png -网络配置中的未知部分.

The error I have is: http://c2n.me/3hSHqvR.png - unknown section in web config.

如果我删除所有这些部分,则会遇到另一个运行时错误: http://c2n.me/3hSI745.png -配置错误.

If I remove all these sections, I have another runtime error: http://c2n.me/3hSI745.png - config error.

我尝试使用settings.WithSystemRuntimeCacheHandle()而不是settings.WithMemcachedCacheHandle(),它在没有任何配置节的情况下也可以正常工作.但是在这种情况下,每次重新启动应用程序时都会清除我的缓存.我想要的是-将缓存存储在memcached存储中,与我的应用程序没有任何关系.

I tried to use settings.WithSystemRuntimeCacheHandle() instead of settings.WithMemcachedCacheHandle() and it works fine without any config sections. But in this case, my cache is cleared every time I restart my app. And what I want is - store cache in memcached storage, without any relation to my application.

因此,如果您有一些有关如何在CacheManager中使用memcached的示例或小型教程-我将不胜感激.

So if you have some examples or small tutorial of how to use memcached with CacheManager - I will be much appreciated.

提前谢谢!

推荐答案

关于<cache name="memcached">部分的错误,很可能您没有在配置文件中使用该名称定义任何部分. 至少没有类似的节来自CacheManager或enyim.

Regarding the error for the <cache name="memcached"> section , most likely you have not defined any section inside your configuration file with that name. At least there is no section like that coming from CacheManager nor from enyim.

然后关于内存缓存句柄.句柄的名称必须与该部分匹配,以便CacheManager可以选择配置. 默认值为您拥有的enyim.com/memcached.因此,您可以将enyim.com/memcacheddefault作为memcached缓存句柄的名称.

Then regarding the memcached handle. The name of the handle must match the section so that CacheManager can pick up the configuration. The default is enyim.com/memcached which you have. So you could either put enyim.com/memcached or default as the name of the memcached cache handle.

CacheFactory.Build("memcached", settings => settings
    .WithMemcachedCacheHandle("enyim.com/memcached"));

让我知道这是否对您有用.

Let me know if this works for you.

我知道这还没有很好的记录.我可能会在有空的时候添加一些东西;)

I know this is not very well documented, yet. I might add something when I find some time ;)

这篇关于CacheManager memcached配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆