private static void RegisterStaticCache(FieldInfo field) { var attribute = (PeekInCacheAttribute)field.GetCustomAttribute(typeof(PeekInCacheAttribute)); var classCache = field.GetValue(null); CacheRefernceStore.Register(attribute.CacheName, classCache); }
private static void RegisterAspNetCoreDefaultMemoryCache(FieldInfo field) { var attribute = (PeekInCacheAttribute)field.GetCustomAttribute(typeof(PeekInCacheAttribute)); var classCache = new PlaceholderMemoryCache(attribute.CacheName); CacheRefernceStore.Register(attribute.CacheName, classCache); }
public static IServiceCollection PeekInAClass( this IServiceCollection service, Type classType) { var classFields = classType.GetRuntimeFields() .Where(x => x.GetCustomAttribute <PeekInCacheAttribute>() != null).ToArray(); foreach (var field in classFields) { var attribute = (PeekInCacheAttribute)field.GetCustomAttribute(typeof(PeekInCacheAttribute)); var classCache = field.GetValue(null); CacheRefernceStore.Register(attribute.CacheName, classCache); } return(service); }
private static object DetermineSerialzableCache(string cacheName) { object cache = CacheRefernceStore.GetCache(cacheName); var type = cache.GetType(); if (type.IsSerializable) { return(cache); } if (type.Name.Equals("MemoryCache")) { return(ExtractSerialzableCacheFromMemoryCache(cache)); } if (type.Name.Equals("PlaceholderMemoryCache")) { return(ExtractSerialzableCacheFromDefaultMemoryCache(cache)); } return(null); }
private static string RequestPeekInCacheContent(HttpRequest request) { if (request.Method != "GET") { return(null); } if (!request.Path.StartsWithSegments(new PathString("/PeekInCache"))) { return(null); } var cacheName = request.Path.Value.Split('/').Last(); if (!CacheRefernceStore.Exists(cacheName)) { return(null); } var cache = DetermineSerialzableCache(cacheName); return(cache != null?JsonConvert.SerializeObject(cache) : null); }