Greetings.
Has anyone had any success integrating EFSecondLevelCache.Core and their Redis setup? It's a recommended tool by Microsoft if you want to introduce caching on EntityFrameworkCore.
Abp/Az offers entity level caching out of the box, but it doesn't provide query result caching inherently, so it's either go write a lot of code or try to integrate something like EFSecondLevelCache.Core into Abp so that I can cache a query result easily like this:
var result = _repository.GetAll().Where(x=>x.Something>5).Cacheable().ToList();
That Cacheable extension is incredibly nice and simplifies me having to manually add items to Redis, manage unique key names for each query, etc.
I added their code to Startup as per their instructions:
`services.AddEFSecondLevelCache();
// Add Redis cache service provider
var jss = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
const string redisConfigurationKey = "redis";
string connectionString = _appConfiguration["Abp:RedisCache:ConnectionString"];
services.AddSingleton(typeof(ICacheManagerConfiguration),
new CacheManager.Core.ConfigurationBuilder()
.WithJsonSerializer(serializationSettings: jss, deserializationSettings: jss)
.WithUpdateMode(CacheUpdateMode.Up)
.WithRedisConfiguration(redisConfigurationKey, config =>
{
config.WithAllowAdmin()
.WithDatabase(0) // (int.Parse(_appConfiguration["Abp:RedisCache:DatabaseId"]))
.WithEndpoint(connectionString, 6379);
})
.WithMaxRetries(100)
.WithRetryTimeout(50)
.WithRedisCacheHandle(redisConfigurationKey)
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMinutes(10))
.Build());
services.AddSingleton(typeof(ICacheManager<>), typeof(BaseCacheManager<>));`
and
app.UseEFSecondLevelCache();
but as soon as try using the .Cacheable() like the above line is called I get CastleWindsor errors:
Exception thrown: 'Castle.MicroKernel.ComponentActivator.ComponentActivatorException' in System.Private.CoreLib.dll
Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter: 2018-11-20 14:49:30,995 [12] ERROR Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter ComponentActivator: could not instantiate CacheManager.Core.BaseCacheManager1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] Castle.MicroKernel.ComponentActivator.ComponentActivatorException: ComponentActivator: could not instantiate CacheManager.Core.BaseCacheManager
1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] ---> System.Exception: Could not instantiate CacheManager.Core.BaseCacheManager1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Connection to 'statuscast-test.redis.cache.windows.net:6380,allowAdmin=True,connectTimeout=5000,password=****,ssl=False,abortConnect=False,connectRetry=10,proxy=None' failed. at CacheManager.Core.BaseCacheManager
1..ctor(String name, ICacheManagerConfiguration configuration)
at CacheManager.Core.BaseCacheManager1..ctor(ICacheManagerConfiguration configuration) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at Castle.Core.Internal.ReflectionUtil.Instantiate[TBase](Type subtypeofTBase, Object[] ctorArgs) --- End of inner exception stack trace --- at Castle.Core.Internal.ReflectionUtil.Instantiate[TBase](Type subtypeofTBase, Object[] ctorArgs) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType) --- End of inner exception stack trace --- at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Handlers.DefaultGenericHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext) at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy, Boolean ignoreParentContext) at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments) at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional) in D:\Github\castle-windsor-ms-adapter\src\Castle.Windsor.MsDependencyInjection\ScopedWindsorServiceProvider.cs:line 55 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at EFSecondLevelCache.Core.EFCachedQueryExtensions.configureProviders() at EFSecondLevelCache.Core.EFCachedQueryExtensions.Cacheable[TType](IQueryable
1 query, String saltKey, EFCacheDebugInfo debugInfo)
at StatusCast.EntityFrameworkCore.Repositories.IncidentRepository.GetFullAsync(Int64 id) in C:\src\statuscast\server.v3\src\StatusCast.EntityFrameworkCore\Incidents\IncidentsRepository.cs:line 30
at Abp.Threading.InternalAsyncHelper.AwaitTaskWithPostActionAndFinallyAndGetResult[T](Task1 actualReturnValue, Func
1 postAction, Action1 finalAction) at StatusCast.Incidents.IncidentAppService.GetIncident(Int64 incidentId) in C:\src\statuscast\server.v3\src\StatusCast.Application\Incidents\IncidentAppService.cs:line 126 at Abp.Threading.InternalAsyncHelper.AwaitTaskWithPostActionAndFinallyAndGetResult[T](Task
1 actualReturnValue, Func1 postAction, Action
1 finalAction)
at Abp.Threading.InternalAsyncHelper.AwaitTaskWithFinallyAndGetResult[T](Task1 actualReturnValue, Action
1 finalAction)
at StatusCast.Web.Controllers.IncidentController.GetIncident(Int64 id) in C:\src\statuscast\server.v3\src\StatusCast.Web.Core\Controllers\IncidentController.cs:line 39
at lambda_method(Closure , Object )
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
StatusCastExceptionHandler: Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter, 11/20/2018 7:49:31 PM, ComponentActivator: could not instantiate CacheManager.Core.BaseCacheManager`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor: 2018-11-20 14:49:31,048 [12] INFO Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'.
4 Answer(s)
-
0
Hi @statuscast
Your problem might be related to https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3146. Which version of ABP do you use ?
-
0
Sorry for late response. We are just going to try and use the native Abp Redis caching. Trying to use DI for some third party modules has turned out to be a nightmare.
-
0
@statuscast So, are you still having this problem ?
-
0
Nope, we gave up. Couldn't get it to work.