This project is read-only.

Strongly typed cache

Feb 20, 2008 at 1:29 PM
I have always been bothered by the fact that the ASP.NET cache uses "objects" which forces us to box and unbox cached items. I see that the caching module in SharpCore mimics this behavior so I was wondering if we could improve this behavior a little bit. For example, what if the "Add" method in the Cache.cs class had the following signature:
public static void Add<T>(string context, string key, T item)
Feb 20, 2008 at 1:41 PM
of course, we would also need to modify the Get method signature like so:
public static T Get<T>(string context, string key)
Jun 29, 2009 at 1:35 AM

I think the real reason that ASP.NET's cache uses System.Object is so that it can store instances of more than one type.  Assuming that the cache implemented a strongly-typed interface with generics, it would be restricted to a single type (or it's subtypes).  Given that most caches store a variety of data, I don't think it makes much sense to change the current design and implementation to be more strongly typed.