/// <summary> /// Returns EntityType object from cache. If entityType does not already exist in cache, it /// will be read and added to cache /// </summary> /// <param name="id"></param> /// <returns></returns> public static EntityTypeCache Read(int id) { string cacheKey = EntityTypeCache.CacheKey(id); ObjectCache cache = MemoryCache.Default; EntityTypeCache entityType = cache[cacheKey] as EntityTypeCache; if (entityType != null) { return(entityType); } else { Rock.Model.EntityTypeService entityTypeService = new Rock.Model.EntityTypeService(); Rock.Model.EntityType entityTypeModel = entityTypeService.Get(id); if (entityTypeModel != null) { entityType = CopyModel(entityTypeModel); cache.Set(cacheKey, entityType, new CacheItemPolicy()); return(entityType); } else { return(null); } } }
/// <summary> /// Copies the model. /// </summary> /// <param name="entityTypeModel">The field type model.</param> /// <returns></returns> public static EntityTypeCache CopyModel(Rock.Model.EntityType entityTypeModel) { EntityTypeCache entityType = new EntityTypeCache(entityTypeModel); // update static dictionary object with name/id combination if (entityTypes.ContainsKey(entityType.Name)) { entityTypes[entityType.Name] = entityType.Id; } else { entityTypes.Add(entityType.Name, entityType.Id); } return(entityType); }
/// <summary> /// Reads the specified field type model. /// </summary> /// <param name="entityTypeModel">The field type model.</param> /// <returns></returns> public static EntityTypeCache Read(Rock.Model.EntityType entityTypeModel) { string cacheKey = EntityTypeCache.CacheKey(entityTypeModel.Id); ObjectCache cache = MemoryCache.Default; EntityTypeCache entityType = cache[cacheKey] as EntityTypeCache; if (entityType != null) { return(entityType); } else { entityType = EntityTypeCache.CopyModel(entityTypeModel); cache.Set(cacheKey, entityType, new CacheItemPolicy()); return(entityType); } }
private EntityTypeCache(Rock.Model.EntityType model) : base(model) { }