public HybridCacheService(HybridCacheOptions options, ILogger <HybridCacheService> logger) { var cacheOptions = new Imazen.HybridCache.HybridCacheOptions(options.DiskCacheDirectory) { AsyncCacheOptions = new AsyncCacheOptions() { MaxQueuedBytes = Math.Max(0, options.QueueSizeLimitInBytes), WriteSynchronouslyWhenQueueFull = true, MoveFileOverwriteFunc = (from, to) => File.Move(from, to, true) }, CleanupManagerOptions = new CleanupManagerOptions() { MaxCacheBytes = Math.Max(0, options.CacheSizeLimitInBytes), MinCleanupBytes = Math.Max(0, options.MinCleanupBytes), MinAgeToDelete = options.MinAgeToDelete.Ticks > 0 ? options.MinAgeToDelete : TimeSpan.Zero, } }; var database = new MetaStore(new MetaStoreOptions(options.DiskCacheDirectory) { Shards = Math.Max(1, options.DatabaseShards), MaxLogFilesPerShard = 3, }, cacheOptions, logger); cache = new Imazen.HybridCache.HybridCache(database, cacheOptions, logger); }
public HybridCache(ICacheDatabase cacheDatabase, HybridCacheOptions options, ILogger logger) { this.logger = logger; Database = cacheDatabase; PathBuilder = new HashBasedPathBuilder(options.PhysicalCacheDir, options.Subfolders, Path.DirectorySeparatorChar, ".jpg"); options.CleanupManagerOptions.MoveFileOverwriteFunc = options.CleanupManagerOptions.MoveFileOverwriteFunc ?? options.AsyncCacheOptions.MoveFileOverwriteFunc; CleanupManager = new CleanupManager(options.CleanupManagerOptions, Database, logger, PathBuilder); AsyncCache = new AsyncCache(options.AsyncCacheOptions, CleanupManager, PathBuilder, logger); }