A better way to obtain objects from cache

Last week I have posted a better approach to getting field values from an SPListItem. Today I’ve found out that you can actually use almost the same approach to get stuff from the ASP.NET cache.

C sharp code of the try get value method

Once again it’s an extension method which can be used in an intuitive way. The only difference is the type of the key: while getting a field value we’ve been using a GUID and now we’re using a string.

Using the above method you can now easily obtain various items from the cache in a type-safe manner:

Two examples of using the try get value method to obtain a datetime object and a xsl compiled transform object from the asp.net cache

Keep it simple!

Technorati Tags: ASP.NET, Cache


comments powered by Disqus