/// <summary> /// Reads the specified GUID. /// </summary> /// <param name="guid">The GUID.</param> /// <returns></returns> public static LayoutCache Read(Guid guid) { ObjectCache cache = MemoryCache.Default; object cacheObj = cache[guid.ToString()]; if (cacheObj != null) { return(Read((int)cacheObj)); } else { var LayoutService = new LayoutService(); var LayoutModel = LayoutService.Get(guid); if (LayoutModel != null) { LayoutModel.LoadAttributes(); var Layout = new LayoutCache(LayoutModel); var cachePolicy = new CacheItemPolicy(); cache.Set(LayoutCache.CacheKey(Layout.Id), Layout, cachePolicy); cache.Set(Layout.Guid.ToString(), Layout.Id, cachePolicy); return(Layout); } else { return(null); } } }
/// <summary> /// Returns Layout object from cache. If Layout does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static LayoutCache Read(int id) { string cacheKey = LayoutCache.CacheKey(id); ObjectCache cache = MemoryCache.Default; LayoutCache Layout = cache[cacheKey] as LayoutCache; if (Layout != null) { return(Layout); } else { var LayoutService = new LayoutService(); var LayoutModel = LayoutService.Get(id); if (LayoutModel != null) { LayoutModel.LoadAttributes(); Layout = new LayoutCache(LayoutModel); var cachePolicy = new CacheItemPolicy(); cache.Set(cacheKey, Layout, cachePolicy); cache.Set(Layout.Guid.ToString(), Layout.Id, cachePolicy); return(Layout); } else { return(null); } } }
/// <summary> /// Adds Layout model to cache, and returns cached object /// </summary> /// <param name="LayoutModel"></param> /// <returns></returns> public static LayoutCache Read(Layout LayoutModel) { string cacheKey = LayoutCache.CacheKey(LayoutModel.Id); ObjectCache cache = MemoryCache.Default; LayoutCache Layout = cache[cacheKey] as LayoutCache; if (Layout != null) { return(Layout); } else { Layout = new LayoutCache(LayoutModel); var cachePolicy = new CacheItemPolicy(); cache.Set(cacheKey, Layout, cachePolicy); cache.Set(Layout.Guid.ToString(), Layout.Id, cachePolicy); return(Layout); } }
/// <summary> /// Removes Layout from cache /// </summary> /// <param name="id"></param> public static void Flush(int id) { ObjectCache cache = MemoryCache.Default; cache.Remove(LayoutCache.CacheKey(id)); }
/// <summary> /// Removes Layout from cache /// </summary> /// <param name="id"></param> public static void Flush(int id) { FlushCache(LayoutCache.CacheKey(id)); }
/// <summary> /// Adds Layout model to cache, and returns cached object /// </summary> /// <param name="LayoutModel"></param> /// <returns></returns> public static LayoutCache Read(Layout LayoutModel) { return(GetOrAddExisting(LayoutCache.CacheKey(LayoutModel.Id), () => LoadByModel(LayoutModel))); }
/// <summary> /// Returns Layout object from cache. If Layout does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id">The identifier.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> public static LayoutCache Read(int id, RockContext rockContext = null) { return(GetOrAddExisting(LayoutCache.CacheKey(id), () => LoadById(id, rockContext))); }