/// <summary> /// Reads the specified GUID. /// </summary> /// <param name="guid">The GUID.</param> /// <returns></returns> public static GroupTypeCache Read(Guid guid) { ObjectCache cache = MemoryCache.Default; object cacheObj = cache[guid.ToString()]; if (cacheObj != null) { return(Read((int)cacheObj)); } else { var groupTypeService = new GroupTypeService(); var groupTypeModel = groupTypeService.Get(guid); if (groupTypeModel != null) { groupTypeModel.LoadAttributes(); var groupType = new GroupTypeCache(groupTypeModel); var cachePolicy = new CacheItemPolicy(); cache.Set(GroupTypeCache.CacheKey(groupType.Id), groupType, cachePolicy); cache.Set(groupType.Guid.ToString(), groupType.Id, cachePolicy); return(groupType); } else { return(null); } } }
/// <summary> /// Returns GroupType object from cache. If groupType does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static GroupTypeCache Read(int id) { string cacheKey = GroupTypeCache.CacheKey(id); ObjectCache cache = MemoryCache.Default; GroupTypeCache groupType = cache[cacheKey] as GroupTypeCache; if (groupType != null) { return(groupType); } else { var groupTypeService = new GroupTypeService(); var groupTypeModel = groupTypeService.Get(id); if (groupTypeModel != null) { groupTypeModel.LoadAttributes(); groupType = new GroupTypeCache(groupTypeModel); var cachePolicy = new CacheItemPolicy(); cache.Set(cacheKey, groupType, cachePolicy); cache.Set(groupType.Guid.ToString(), groupType.Id, cachePolicy); return(groupType); } else { return(null); } } }
/// <summary> /// Reads the specified field type model. /// </summary> /// <param name="groupTypeModel">The field type model.</param> /// <returns></returns> public static GroupTypeCache Read(GroupType groupTypeModel) { string cacheKey = GroupTypeCache.CacheKey(groupTypeModel.Id); ObjectCache cache = MemoryCache.Default; GroupTypeCache groupType = cache[cacheKey] as GroupTypeCache; if (groupType != null) { return(groupType); } else { groupType = new GroupTypeCache(groupTypeModel); var cachePolicy = new CacheItemPolicy(); cache.Set(cacheKey, groupType, cachePolicy); cache.Set(groupType.Guid.ToString(), groupType.Id, cachePolicy); return(groupType); } }
/// <summary> /// Removes groupType from cache /// </summary> /// <param name="id"></param> public static void Flush(int id) { FlushCache(GroupTypeCache.CacheKey(id)); }
/// <summary> /// Reads the specified field type model. /// </summary> /// <param name="groupTypeModel">The field type model.</param> /// <returns></returns> public static GroupTypeCache Read(GroupType groupTypeModel) { return(GetOrAddExisting(GroupTypeCache.CacheKey(groupTypeModel.Id), () => LoadByModel(groupTypeModel))); }
/// <summary> /// Returns GroupType object from cache. If groupType 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 GroupTypeCache Read(int id, RockContext rockContext = null) { return(GetOrAddExisting(GroupTypeCache.CacheKey(id), () => LoadById(id, rockContext))); }
/// <summary> /// Removes groupType from cache /// </summary> /// <param name="id"></param> public static void Flush(int id) { FlushCache(GroupTypeCache.CacheKey(id)); FlushCache("Rock:GroupType:All"); }
/// <summary> /// Removes groupType from cache /// </summary> /// <param name="id"></param> public static void Flush(int id) { ObjectCache cache = MemoryCache.Default; cache.Remove(GroupTypeCache.CacheKey(id)); }