开发者

In-process caching library in c# other then MS ones?

Does someone knows a library fo开发者_如何转开发r in-process caching, other than MS ASP.NET cache and ENTLib, with at least two features: - expiring time; - object dependency.


I implemented a thread safe pseudo LRU for in memory caching. It's simpler and faster than using Memory cache - performance is very close to ConcurrentDictionary (10x faster than memory cache, and zero memory allocs for hits).

Usage of the LRU looks like this (just like dictionary but you need to give capacity - it's a bounded cache):

int capacity = 666;
var timeToLive = DateTime.FromMinutes(5);
var lru = new ConcurrentTLru<int, SomeItem>(capacity, timeToLive);

var value = lru.GetOrAdd(1, (k) => new SomeItem(k));

GitHub: https://github.com/bitfaster/BitFaster.Caching

Install-Package BitFaster.Caching

My advice would be to cache object graphs (e.g. classes with properties that reference other classes) in an LRU, so that you can evict things at well defined nodes in the dependency tree by simply updating the object. You will naturally end up with something that is easier to understand and doesn't dependency cycles.


There are a few cache providers over at Codeplex, SharedCache seems promising: http://sharedcache.codeplex.com/.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜