Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jonathan L Folland 32 posts 174 karma points
    May 28, 2015 @ 02:47
    Jonathan L Folland
    0

    Default Result in Umbraco.Core.Cache.CacheProviderExtensions

    Not sure if this is the right place, but I would like to recommend removing the default result from the cache provider extension:

    public static T GetCacheItem<T>(this ICacheProvider provider, string cacheKey)
            {
                var result = provider.GetCacheItem(cacheKey);
                if (result == null)
                {
                    return default(T);
                }
                return result.TryConvertTo<T>().Result;
            }

    Notice how the cache will return a default if the get does not return a result. This can create unknown results on behalf of consumers of this service. They may think they have gotten the correct object, but in fact have gotten a default value. The consume should make a decision what to do in the event of a null result. The fix here is to change return default(T) to return null.

     

Please Sign in or register to post replies

Write your reply to:

Draft