Copied to clipboard

Flag this post as spam?

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


  • Carl Jackson 139 posts 478 karma points
    Apr 12, 2016 @ 08:05
    Carl Jackson
    0

    Umbraco request cache

    Hi all.

    I have been attempting to save an object on the Umbraco request cache as the same object is accessed several times per request from different services.

    I can't find much documentation on the request cache itself but my understand is that the object is cached for the current users http request and then discarded.

    Using the following code however the callback function is run every time during the request and the object does not apear to get cached at all.

    return ApplicationContext.Current.ApplicationCache.RequestCache
            .GetCacheItem<ApiResponse<T>>("usercache." + username, () =>
            {                
                    return RestClient.GetUser(username);                
            });
        }
    

    Any help understanding this is appreciated.

    Thanks

    Carl

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 12, 2016 @ 08:32
    Dave Woestenborghs
    0

    Hi Carl,

    This code seems okay to me. But just to be sure.

    Can you use this :

    return ApplicationContext.Current.ApplicationCache.RequestCache
            .GetCacheItem("usercache." + username, () =>
            {                
                    return RestClient.GetUser(username);                
            });
        }
    

    That is how we use it.

    Dave

  • Carl Jackson 139 posts 478 karma points
    Apr 12, 2016 @ 11:27
    Carl Jackson
    0

    Hi Dave,

    I would need to cast to ensure stop errors. but I'll give it a go.

    return (ApiResponse<T>)ApplicationContext.Current.ApplicationCache.RequestCache
        .GetCacheItem("usercache." + username, () =>
        {                
                return RestClient.GetUser(username);                
        });
    }
    
  • Carl Jackson 139 posts 478 karma points
    Apr 12, 2016 @ 12:37
    Carl Jackson
    0

    No difference when I change to the above, still drops into tha callback method every time.

    Any other suggestions anyone? The Runtime cache is working as expected for other things I just wanted to use a per request cche for the actual user rather than Timed.

    Thanks

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 12, 2016 @ 12:41
    Dave Woestenborghs
    0

    Hi Carl,

    I just remembered something. Some versions of Umbraco had a issue with Request cache. I know 7.3.8 has this issue. And I believe one of the 7.4.x has it too.

    See this issue : http://issues.umbraco.org/issue/U4-8027

    If you are running on 7.3.8 see the last comment from Jeroen Breuer on how we tackled the issue.

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft