multiple configuration not working

Issue #37 on hold
Former user created an issue

i am using Glav cache adapter 4.0 for data caching on web farm. For better performance, i am storing cached data in memory on individual server and store the cache key along with time stamp for invalidation on Redis. while fetching data from memory cache, i need to verify on Redis if the cache key is still valid. for this i need to have 2 config setting for glav adapter, one for memory cache on web server and other for central Redis data store. Here problem i am facing looks like Glav adapter is is not able to switch between different config settings.

below is sample methods using both the config but it looks internal void InvalidateCacheIfOldTimaStamp(string key) { if (GateConfig.Central_IsCacheEnabled == false) return; Dictionary<string, DateTime> data = new Dictionary<string, DateTime>(); data = cacheProvider.Get<Dictionary<string, DateTime>>("C_" + key, new TimeSpan(0, 1440, 0), () => { data.Add(key, DateTime.Now); return data; });

        Dictionary<string, DateTime> data1 = new Dictionary<string, DateTime>();
        data1 = centralCacheProvider.Get<Dictionary<string, DateTime>>("M_" + key, new TimeSpan(0, 1440, 0), () =>
        {
            data1.Add(key, DateTime.Now.AddDays(-1));
            return data;
        });

        if (data[key] < data1[key])
        {
            cacheProvider.InvalidateCacheItem(key);  
        }
    }

    protected internal ICacheProvider cacheProvider
    {
        get
        {
            var cp = AppServices.Cache;
            cp.CacheConfiguration.CacheToUse = Config.CachingType;
            cp.CacheConfiguration.IsCacheEnabled = Config.IsCacheEnabled;
            cp.CacheConfiguration.IsCacheDependencyManagementEnabled = Config.Cache_IsCacheDependencyManagementEnabled;
            cp.CacheConfiguration.DependencyManagerToUse = Config.Cache_DependencyManagerToUse;
            cp.CacheConfiguration.DistributedCacheServers = Config.Cache_DistributedCacheServers;
            cp.CacheConfiguration.CacheSpecificData = Config.Cache_CacheSpecificData;
            return cp;
        }
    }

    protected internal ICacheProvider centralCacheProvider
    {
        get
        {
            var cp = AppServices.Cache;
            cp.CacheConfiguration.CacheToUse = Config.Central_CacheToUse;
            cp.CacheConfiguration.IsCacheEnabled = Config.Central_IsCacheEnabled;
            cp.CacheConfiguration.IsCacheDependencyManagementEnabled = Config.Central_IsCacheDependencyManagementEnabled;
            cp.CacheConfiguration.DependencyManagerToUse = Config.Central_DependencyManagerToUse;
            cp.CacheConfiguration.DistributedCacheServers = Config.Central_DistributedCacheServers;
            cp.CacheConfiguration.CacheSpecificData = Config.Central_CacheSpecificData;
            return cp;
        }
    }

Comments (2)

  1. Paul Glavich repo owner

    Hi,

    Sorry for the delay, I missed this issue. Is this still a problem for you? There is an example of how to switch config in the ExampleUsage project as part of the sample. Look for the line:

    AppServices.SetConfig(new CacheConfig() { CacheToUse = "memcached", DistributedCacheServers = "localhost:11211" });
    
  2. Log in to comment