我将在我的CacheManager项目中使用.net。问题是我找不到CacheManager.Memcached使用的任何例子。
我就是这样用它的:
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:
<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 - web中未知的部分。
如果删除所有这些部分,则会出现另一个运行时错误:http://c2n.me/3hSI745.png - config错误。
我尝试使用settings.WithSystemRuntimeCacheHandle()而不是settings.WithMemcachedCacheHandle(),没有任何配置部分,它工作得很好。但在这种情况下,每次重新启动应用程序时,我的缓存都会被清除。我想要的是-在memcached存储中存储缓存,而不与我的应用程序有任何关系。
因此,如果您有一些关于如何在CacheManager中使用memcached的示例或小教程,我将不胜感激。
提前感谢!
发布于 2015-05-18 23:07:16
关于<cache name="memcached">部分的错误,很可能您还没有在配置文件中使用该名称定义任何节。至少没有像这样的部分来自CacheManager,也没有来自enyim。
然后关于memcached句柄。句柄的名称必须与该节匹配,以便CacheManager能够获取配置。默认的是enyim.com/memcached,这是您拥有的。因此,您可以将enyim.com/memcached或default作为memcached缓存句柄的名称。
喜欢
CacheFactory.Build("memcached", settings => settings
.WithMemcachedCacheHandle("enyim.com/memcached"));如果这对你有用的话请告诉我。
我知道这还不是很好的记录。当我有时间的时候,我可能会添加一些东西;)
https://stackoverflow.com/questions/30308226
复制相似问题