private static CachingJsonSerializerSettings GetSerializerSettings() { var serializerSettings = new CachingJsonSerializerSettings { Converters = new List <JsonConverter>(), ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }, Formatting = Formatting.Indented }; return(serializerSettings); }
public CacheService( IConnectionMultiplexer connectionMultiplexer, IOptionsMonitor <ColidCacheOptions> cacheOptions, IHostEnvironment environment, CachingJsonSerializerSettings serializerSettings, ILogger <CacheService> logger) { _environment = environment; _configuredExpirationTime = TimeSpan.FromSeconds(cacheOptions.CurrentValue.AbsoluteExpirationRelativeToNow); _serializerSettings = serializerSettings; _connectionMultiplexer = connectionMultiplexer; _cache = _connectionMultiplexer.GetDatabase(); _logger = logger; }
public static IServiceCollection AddCacheModule(this IServiceCollection services, IConfiguration configuration, CachingJsonSerializerSettings cachingJsonSerializerSettings) { var cacheOptions = ParseCachingConfiguration(configuration); if (!cacheOptions.Enabled) { return(AddNoCacheModule(services)); } if (cacheOptions.UseInMemory) { return(AddMemoryCacheModule(services, configuration, cachingJsonSerializerSettings)); } return(AddDistributedCacheModule(services, configuration, cachingJsonSerializerSettings)); }
public CacheService( IConnectionMultiplexer connectionMultiplexer, IOptionsMonitor <ColidCacheOptions> cacheOptions, IHostEnvironment environment, CachingJsonSerializerSettings serializerSettings, ILogger <CacheService> logger) { _environment = environment; _configuredExpirationTime = TimeSpan.FromSeconds(cacheOptions.CurrentValue.AbsoluteExpirationRelativeToNow); _serializerSettings = serializerSettings; _connectionMultiplexer = connectionMultiplexer; _cache = _connectionMultiplexer.GetDatabase(); _logger = logger; int minWorker, minIOC; ThreadPool.GetMinThreads(out minWorker, out minIOC); _logger.LogInformation("Threading set to minWorker: {minWorker}, minIOC: {minIOC}", minWorker, minIOC); }
/// <summary> /// This will register all the supported functionality by Repositories module for local environments. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> object for registration.</param> /// <param name="configuration">The <see cref="IConfiguration"/> object for registration.</param> public static IServiceCollection RegisterLocalRepositoriesModule(this IServiceCollection services, IConfiguration configuration) { services.AddBaseRepositoriesModule(configuration); services.AddSingletonGraphModule(configuration); var serializerSettings = new CachingJsonSerializerSettings { Converters = new List <JsonConverter>(), ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }, Formatting = Formatting.Indented }; serializerSettings.Converters.Add(new EntityPropertyConverter()); services.AddMemoryCacheModule(configuration, serializerSettings); return(services); }
/// <summary> /// This will register memory cache functionality. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> object for registration.</param> /// <param name="configuration">The <see cref="IConfiguration"/> object for registration.</param> public static IServiceCollection AddMemoryCacheModule(this IServiceCollection services, IConfiguration configuration, CachingJsonSerializerSettings cachingJsonSerializerSettings) { Contract.Requires(configuration != null && cachingJsonSerializerSettings != null); var cacheOptions = ParseCachingConfiguration(configuration); if (!cacheOptions.Enabled) { return(AddNoCacheModule(services)); } services.AddMemoryCache(); services.AddSingleton(cachingJsonSerializerSettings); services.AddSingleton <ICacheService, InMemoryCacheService>(); services.Configure <ColidCacheOptions>(configuration.GetSection(nameof(ColidCacheOptions))); #pragma warning disable CA1303 // Do not pass literals as localized parameters Console.WriteLine($"- Caching: InMemory"); #pragma warning restore CA1303 // Do not pass literals as localized parameters return(services); }
/// <summary> /// This will register distributed cache functionality. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> object for registration.</param> /// <param name="configuration">The <see cref="IConfiguration"/> object for registration.</param> public static IServiceCollection AddDistributedCacheModule(this IServiceCollection services, IConfiguration configuration, CachingJsonSerializerSettings cachingJsonSerializerSettings) { Contract.Requires(configuration != null && cachingJsonSerializerSettings != null); var cacheOptions = ParseCachingConfiguration(configuration); if (!cacheOptions.Enabled) { return(AddNoCacheModule(services)); } services.AddSingleton(cachingJsonSerializerSettings); services.AddSingleton <ICacheService, CacheService>(); services.Configure <ColidCacheOptions>(configuration.GetSection(nameof(ColidCacheOptions))); var connectionMultiplexer = CreateConnectionMultiplexer(configuration); services.AddSingleton <IConnectionMultiplexer>(connectionMultiplexer); return(services); }