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
    Naman
    0

    Hi All,

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

    ApplicationContext.Current.ApplicationCache.RuntimeCache

    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 2999 posts 13138 karma points MVP 6x admin c-trib
    Apr 06, 2016 @ 14:33
    Jeavon Leopold
    1

    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 194 posts 426 karma points
    Jul 01, 2016 @ 08:26
    Jules
    0

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

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

    Jules

Please Sign in or register to post replies

Write your reply to:

Draft