在.NET-Core
目前的项目中是使用 Memcached
来进行缓存的存取的,但是最近在使用时有点疑惑的地方:
有很多的CacheKey,我总不能这样写把
//Save key
_cache.Add("key1");
_cache.Add("key2");
_cache.Add("Key3");
...
//remove key
_cache.Remove("key1");
_cache.Remove("key2");
_cache.Remove("key3");
我目前采取的做法是,抽离出来一个 CacheManage
类,里面进行Add
和 Remove
的集中操作(代码示例如下):
//移除key的代码
Task RemoveCache(IEnumerable<string> cacheKeyList)
{
var tasks = cacheKeyList.Select(cacheKey=>_cache.RemoveAsync(cacheKey)).Cast<Task>().ToList();
await Task.WhenAll(tasks);
}
上面的代码,我还是觉得有点不够理想;
我想请问一下大家在项目中是如何处理缓存相关的,是否有示例项目代码供参考?
相关问题
- Dotnet Core API - Get the URL of a controller meth
- How to specify memcache server to Rack::Session::M
- Why am I unable to run dotnet tool install --globa
- Singleton with AsyncLocal vs Scope Service
- What would prevent code running in a Docker contai
相关文章
- DotNet Core console app: An assembly specified in
- EF Core 'another instance is already being tra
- Re-target .NET Core to net471, net 472
- Why is file_get_contents faster than memcache_get?
- Publishing a Self-contained Console app fails
- Calling a .Net Framework 4 (or Mono) assembly from
- Can't get deleted items from OpenLDAP Server u
- proper way to sign .net core assembly
最好的方法是归类,就是对key有规律; http://blog.csdn.net/zhaoxuejie/article/details/7739255
如果非要删除也可以用这个:http://www.iyunv.com/thread-140469-1-1.html
h缓存失效方法.orchard项目里是根据一个什么依赖来做.
没学会.你可以试着看看orchard的缓存模块.
w 我通常是把缓存的key根据业务来进行分类,然后都定义成一个字符串常量放一个类里,常量的命名加上业务前缀