Reputation: 71
Does someone knows a library for in-process caching, other than MS ASP.NET cache and ENTLib, with at least two features: - expiring time; - object dependency.
Upvotes: 4
Views: 484
Reputation: 4711
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.
Upvotes: 1
Reputation: 7803
There are a few cache providers over at Codeplex, SharedCache seems promising: http://sharedcache.codeplex.com/.
Upvotes: 0