dotnetcore / EasyCaching

:boom: EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
MIT License
1.95k stars 322 forks source link

MemoryPacker and Redis #443

Open c5racing opened 1 year ago

c5racing commented 1 year ago

Description

I'm trying to replace the Newtonsoft Serializer with the new MemoryPacker to compare performance. When adding MemoryPacker, with Redis, I get an error any time trying to DI the EasyCachingLibraries

Steps to Reproduce

Register EasyCaching; Attempt to resolve IEasyCachingProviderFactory;

Related code

            services.AddEasyCaching(options =>
            {
                options.UseRedis(config =>
                {
                    config.DBConfig.AllowAdmin = true;
                    config.DBConfig.Endpoints.Add(new EasyCaching.Core.Configurations.ServerEndPoint(redisSettings.Host, redisSettings.Port));
                    config.SerializerName = "mempack";
                    config.DBConfig.ConnectionTimeout = 10000;
                    config.EnableLogging = false;

                    if (!string.IsNullOrWhiteSpace(redisSettings.Password))
                    {
                        config.DBConfig.Password = redisSettings.Password;
                        config.DBConfig.IsSsl = true;
                    }
                }, cacheName).WithMemoryPack(x =>
                {
                    x.StringEncoding = StringEncoding.Utf8;
                }, "mempack");
            });

var providerFactory = serviceProvider.GetRequiredService<IEasyCachingProviderFactory>();

Expected behavior: [What you expected to happen] I would expect to replace Newtonsoft with MessagePack

Actual behavior: [What actually happened] Receive the following error when trying to resolve IEasyCachingProviderFactory

Autofac.Core.DependencyResolutionException HResult=0x80131500 Message=An exception was thrown while activating λ:EasyCaching.Core.IRedisCachingProvider -> λ:EasyCaching.Core.Serialization.IEasyCachingSerializer[] -> λ:EasyCaching.Core.Serialization.IEasyCachingSerializer. Source=Autofac StackTrace: at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.RegistrationPipelineInvokeMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.SharingMiddleware.<>c__DisplayClass5_0.b__0() at Autofac.Core.Lifetime.LifetimeScope.CreateSharedInstance(Guid id, Func1 creator) at Autofac.Core.Lifetime.LifetimeScope.CreateSharedInstance(Guid primaryId, Nullable1 qualifyingId, Func1 creator) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.ResolveOperation.InvokePipeline(ResolveRequest request, DefaultResolveRequestContext requestContext) at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest request) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable1 parameters) at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType, IEnumerable1 parameters) at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType) at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at Caching.CachingProvider..ctor(IOptions1 cacheSettings, IServiceProvider serviceProvider, ILockProvider lockProvider, ILogger1 logger) in C:\Users\admin\source\repos\SRM\src\BuildingBlocks\Caching\CachingProvider.cs:line 42 at Autofac.Core.Activators.Reflection.BoundConstructor.Instantiate()

This exception was originally thrown at this call stack: [External Code]

Inner Exception 1: MissingMethodException: Method not found: 'Void MemoryPack.MemoryPackSerializerOptions.set_StringEncoding(MemoryPack.StringEncoding)'.

catcherwong commented 1 year ago

@c5racing Thanks for your interest in this project.

We will take a look ASAP.

@amiru3f Do you have time to take a look on this issue about MemoryPacker.

dpetlyuk commented 1 year ago

I have same the problem. MissingMethodException: Method not found: 'Void MemoryPack.MemoryPackSerializerOptions.set_StringEncoding(MemoryPack.StringEncoding)'.

c5racing commented 1 year ago

Any updates on this @amiru3f or @catcherwong?

catcherwong commented 1 year ago

@c5racing Could you provide a sample for this issue? I cannot reproduce it.

amiru3f commented 1 year ago

Hey guys Sorry for late response, I was away from my Github account for a long time. Do you still have the problem? I can take a look.

@c5racing