Listing 7.2 Wrapping the cache

0 views
Skip to first unread message

Alan_Huffman

unread,
Feb 16, 2010, 3:42:07 PM2/16/10
to mvc2inaction-discuss
Small point, but should be important in this case

...
public class AspNetCache : ICache
{
public T Get<T>(string key)
{
// this line (see below)
return (T)HttpContext.Current.Cache[key];
}
...

If the HttpContext.Current.Cache[key] is absent (null), would you not
rather:

return HttpContext.Current.Cache[key] as T; // will be null if
not castable instead of throwing exception

Perhaps even better

return HttpContext.Current.Cache.Get(key) as T; // if not
explicitly checking for presence.

Just a suggestion... Fantastic read so far,

Thanks!
Alan

Reply all
Reply to author
Forward
0 new messages