Copied to clipboard

Flag this post as spam?

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

  • Naman 20 posts 101 karma points
    Apr 06, 2016 @ 13:16

    Hi All,

    We had a look at the Umbraco and find that we can access cache by using following class


    In order to add item in to cache we can use method "InsertCacheItem". Can you please let us know the syntax to use this method.

    Also we didn't find method to fetch items from the cache. There are methods like "GetCacheItem" available but these are marked as Obselete. Should we continue to use to use this method or there are some other methods to fetch data from the cache.

  • Jeavon Leopold 3005 posts 13193 karma points MVP 7x admin c-trib
    Apr 06, 2016 @ 14:33
    Jeavon Leopold

    I would recommend you use the below extension method in Umbraco.Cache.Core which will do both the get and the insert (if needed)

    public static T GetCacheItem<T>(this ICacheProvider provider, string cacheKey, Func<T> getCacheItem)

    For example

            var myThing = ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem <List<string>>("MyCacheKey",(() => new List<string>() {"a", "b", "c"}));
  • Jules 204 posts 447 karma points
    Jul 01, 2016 @ 08:26

    As a matter of interest, what is the first () doing in this part of the code above?

      (() => new List<string>() {"a", "b", "c"})


Please Sign in or register to post replies

Write your reply to: