I want to use EF Second Level Cache and change the default cache provider of EF in an ASP.NET MVC project to use Redis instead of its InMemory cache provider.
I have the following sample code for MVC Core:
// Add Redis cache service provider
var jss = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
const string redisConfigurationKey = "redis";
services.AddSingleton(typeof(ICacheManagerConfiguration),
new CacheManager.Core.ConfigurationBuilder()
.WithJsonSerializer(serializationSettings: jss, deserializationSettings: jss)
.WithUpdateMode(CacheUpdateMode.Up)
.WithRedisConfiguration(redisConfigurationKey, config =>
{
config.WithAllowAdmin()
.WithDatabase(0)
.WithEndpoint("localhost", 6379);
})
.WithMaxRetries(100)
.WithRetryTimeout(50)
.WithRedisCacheHandle(redisConfigurationKey)
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMinutes(10))
.Build());
services.AddSingleton(typeof(ICacheManager<>), typeof(BaseCacheManager<>));
My project is not
MVC Core, it isMVC. Also I useStructureMapsas IOC.
Now I have 2 question:
- How should I configure
EFin my project to useRedisas its Second Level Cache Provider (I'm using this package)? - Can I use the saved data in the cache (
Redis) in this way in a separate project on my computer (Sharing cache of an MVC application between several application)?