using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Runtime.Caching; namespace LJProxy { public static class Cache { public static MemoryCache DefaultCache { get { return MemoryCache.Default; } } private static MemoryCache _fileCache = new MemoryCache("FileCache"); public static MemoryCache FileCache { get { return _fileCache; } } public static CacheItemPolicy CreateCacheItemPolicy(TimeSpan? slidingExpiration = null, DateTime? absoluteExpiration = null , List dependencyKeys = null, CacheItemPriority? priority = null) { var cachePolicy = new CacheItemPolicy(); if (slidingExpiration != null) cachePolicy.SlidingExpiration = slidingExpiration.Value; if (absoluteExpiration != null) cachePolicy.AbsoluteExpiration = absoluteExpiration.Value; if (dependencyKeys !=null && dependencyKeys.Count>0 ) { cachePolicy.ChangeMonitors.Add(new HostFileChangeMonitor(dependencyKeys)); } if (priority != null) cachePolicy.Priority = priority.Value; else cachePolicy.Priority = CacheItemPriority.Default; return cachePolicy; } } }