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 35 posts 197 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.

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies