Copied to clipboard

Flag this post as spam?

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


  • Johnathan Le 10 posts 40 karma points
    Jul 02, 2023 @ 04:04
    Johnathan Le
    0

    Use DistributedCache to send ICacheRefresher to Subscriber server not working

    Hi everyone,

    I have the use case which need to clean up RuntimeCache by using ICacheRefresher for all Subscriber servers. I tried on my local machine by setting up Subscriber and SchedulingPublisher via SQL Express, the code is worked. However, I deploy the code to real environment, it isn't working. The Subscriber server cannot subscribe the ICacheRefresher. I wonder it is because of TempFileSystemDirectoryFactory .

    More info: I am suing Umbraco 11.3.1, Host by using EKS, Linux

    Code to notify the ICacheRefresher

    public class RuntimeCacheLoadBalancerRefresher : CacheRefresherBase<RuntimeCacheLoadBalancerRefresherNotification>
    {
        private readonly ILogger<RuntimeCacheLoadBalancerRefresher> _logger;
    
        public static readonly Guid UniqueId = Guid.Parse("XXX-XXX");
    
        public override string Name => "Runtime Cache Load Balancer Refresher";
    
        public override Guid RefresherUniqueId => UniqueId;
    
        public RuntimeCacheLoadBalancerRefresher(
            AppCaches appCaches, 
            IEventAggregator eventAggregator, 
            ICacheRefresherNotificationFactory factory,
            ILogger<RuntimeCacheLoadBalancerRefresher> logger)
        : base(appCaches, eventAggregator, factory)
        {
            _logger = logger;
        }
    
        public override void RefreshAll()
        {
            _logger.LogInformation("Refresh RunTime Cache in the machine name {machineName}", Environment.MachineName);
            AppCaches.RuntimeCache.Clear();
            base.RefreshAll();
        }
    }
    

    Code to send

    DistributedCache.RefreshAll(RuntimeCacheLoadBalancerRefresher.UniqueId);
    

    Subscriber server config

    "CMS": {
        "Global": {
          "Id": "YYY-YYY",
          "SanitizeTinyMce": true
        },
        "Content": {
          "AllowEditInvariantFromNonDefault": true,
          "ContentVersionCleanupPolicy": {
            "EnableCleanup": true
          }
        },
        "Examine":{
          "LuceneDirectoryFactory": "TempFileSystemDirectoryFactory"
        }
      }
    

    SchedulingPublisher server config

    "CMS": {
        "Global": {
          "Id": "YYY-YYY",
          "SanitizeTinyMce": true
        },
        "Content": {
          "AllowEditInvariantFromNonDefault": true,
          "ContentVersionCleanupPolicy": {
            "EnableCleanup": true
          }
        },
        "Examine":{
          "LuceneDirectoryFactory": "SyncedTempFileSystemDirectoryFactory"
        }
      }
    

    Noted: I use the explicit code to register the ServerRole in DI, by reading another option value.

    Also, is it there any possible Umbraco service which support to boardcast the message? I only the keyword IServerMessager but i think it is already used within the DistributedCache class mechanism. Can i consider to use another technique Pub-Sub like RabbitMq to send the notification from BackOffice to Subscriber server?

    Hope you help, Thanks

  • 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