Code Monkey home page Code Monkey logo

Comments (6)

VahidN avatar VahidN commented on July 31, 2024 1

Change the name of your in-memory cache, to something else:

 const string menuLocalCache = "MenuDistributedCache";

Because it's the same as your menuDistributedCache/redis cache and this FirstOrDefault here thinks it's not a distributed cache, which is true. It's an in-memory cache or the in-memory cache wins first(or default).

from efcoresecondlevelcacheinterceptor.

rohan-buechner avatar rohan-buechner commented on July 31, 2024 1

OMG.... thank you... 😑 This has been driving me nuts.... I just wish it wasn't as simple as PEBCAK... my bad. Thanks for explaining how the lib selects the providers.

from efcoresecondlevelcacheinterceptor.

VahidN avatar VahidN commented on July 31, 2024

Try V2.0.0 with this setting:

options.UseEasyCachingCoreProvider(providerName1, isHybridCache: true)

from efcoresecondlevelcacheinterceptor.

rohan-buechner avatar rohan-buechner commented on July 31, 2024

Any Luck with the above? I seem to have the same issue.

Ive used the code as per above... but no luck. I keep getting an error

EasyCaching.HybridCache.NotFoundCachingProviderException: Can not found any distributed caching providers.

I have a similar setup to @jasenf's but I have already set the following to:

options.UseEasyCachingCoreProvider(providerName1, isHybridCache: true)

When using easy caching redis / in memory only... it works... but hybrid, not so much.

from efcoresecondlevelcacheinterceptor.

VahidN avatar VahidN commented on July 31, 2024

Follow this setup. I use it for my tests.

from efcoresecondlevelcacheinterceptor.

rohan-buechner avatar rohan-buechner commented on July 31, 2024

@VahidN I did actually (I found this setup via your tests... but I dont know... just doesnt seem to work)

Im on netcoreapp3.1

and have the following (relevant) modules installed (I havent removed all of the Cache manager modules yet)

   <PackageReference Include="CacheManager.StackExchange.Redis" Version="1.2.0" />
    <PackageReference Include="EasyCaching.Bus.Redis" Version="0.9.0" />
    <PackageReference Include="EasyCaching.HybridCache" Version="0.9.0" />
    <PackageReference Include="EasyCaching.InMemory" Version="0.9.0" />
    <PackageReference Include="EasyCaching.Serialization.Json" Version="0.9.0" />
    <PackageReference Include="EFCoreSecondLevelCacheInterceptor" Version="2.0.0" />
    <PackageReference Include="EasyCaching.Core" Version="0.9.0" />
    <PackageReference Include="EasyCaching.Redis" Version="0.9.0" />

    <PackageReference Include="CacheManager.Core" Version="1.2.0" />
    <PackageReference Include="CacheManager.Microsoft.Extensions.Caching.Memory" Version="1.2.0" />
    <PackageReference Include="CacheManager.Microsoft.Extensions.Configuration" Version="1.2.0" />
    <PackageReference Include="CacheManager.Serialization.Json" Version="1.2.0" />

This is my exact setup:

 public virtual void ConfigureDistributedCaching(IServiceCollection services)
        {
           // localhost / cloud address
            var host = Configuration.GetValue<string>("CacheSettings:Server");
           
           // some other internal extension
            services.AddDistributedRedisCache(option => { option.Configuration = host; });

            const string menuDistributedCache = "MenuDistributedCache";
            const string menuLocalCache = "MenuDistributedCache";
            const string menuHybridCacheProvider = "MenuHybridCache";
            
            services.AddEFSecondLevelCache(options =>
                options
                    .UseEasyCachingCoreProvider(menuHybridCacheProvider, true)
                    .CacheAllQueries(CacheExpirationMode.Sliding, TimeSpan.FromMinutes(60))
                    .DisableLogging(!IsDevelopment)
            );

            // More info: https://easycaching.readthedocs.io/en/latest/Redis/
            services.AddEasyCaching(option =>
            {
                option.WithJson(x =>
                {
                    x.NullValueHandling = NullValueHandling.Ignore;
                    x.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                    x.TypeNameHandling = TypeNameHandling.Auto;
                    x.Converters = new List<JsonConverter>() {new SpecialTypesConverter()};
                }, "json");

                // local
                option.UseInMemory(menuLocalCache);

                // distributed
                option.UseRedis(config =>
                {
                    config.DBConfig.Endpoints.Add(new ServerEndPoint(host, 6379));
                    config.DBConfig.Database = 14;
                    config.EnableLogging = IsDevelopment;
                    config.SerializerName = "json";
                }, menuDistributedCache);

                // combine local and distributed
                option.UseHybrid(config =>
                {
                    config.TopicName = "test-topic";
                    config.EnableLogging = IsDevelopment;
                    config.LocalCacheProviderName = menuLocalCache;
                    config.DistributedCacheProviderName = menuDistributedCache;
                }, menuHybridCacheProvider);

                // use redis bus
                option.WithRedisBus(busConf =>
                {
                    busConf.Database = 15;
                    busConf.Endpoints.Add(new ServerEndPoint(host, 6379));
                    busConf.AllowAdmin = true;
                });
            });

            services.AddControllersWithViews();
        }

from efcoresecondlevelcacheinterceptor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.