Copied to clipboard

Flag this post as spam?

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


  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Nov 07, 2024 @ 17:57
    Alex Skrypnyk
    0

    Refresh Umbraco Memory Cache from code in v10

    Maybe somebody has a code example of how to refresh Memory Cache from code instead of doing it manually in the Settings section.

    Alex

  • Afreed 54 posts 261 karma points
    Nov 08, 2024 @ 07:19
    Afreed
    1

    Hi Alex,

    You can refresh the Umbraco memory cache programmatically by using the DistributedCache service. Here’s a simple example:

    using Umbraco.Cms.Core.Cache;
    public class CacheHelper{
        private readonly DistributedCache _distributedCache;
        public CacheHelper(DistributedCache distributedCache)
        {
            _distributedCache = distributedCache;
        }
        // Method to refresh all published snapshots in the distributed cache, effectively refreshing the memory cache.
        public void RefreshMemoryCache()
        {
            _distributedCache.RefreshAllPublishedSnapshot();
        }}
    

    Hope this is what you are looking for.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Nov 08, 2024 @ 12:03
    Alex Skrypnyk
    0

    Hi Afreed

    Thank you so much, let me test

Please Sign in or register to post replies

Write your reply to:

Draft