While Caching in .NET is a thing of beauty, using it can be a bit cumbersome, and makes my code look clunky. I'm talking about usage like:
if (Cache.Get("myKey") == null) {
Cache.Insert("myKey", getValue());
return Cache.Get("myKey");
}
The class in Cache.cs contains helper methods that make this much easier and cleaner to do
Cache.Get<object>("myKey", () => getValue());
This simply means, return the value in the myKey
key in cache if it exists. If not, execute getValue()
and insert it as myKey
key in the cache.
Also, Cache.Clear()
should come in handy too.