/// <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> /// Reads the specified name. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static EntityTypeCache Read(string name) { if (entityTypes.ContainsKey(name)) { return(Read(entityTypes[name])); } var entityTypeService = new Rock.Model.EntityTypeService(); var entityTypeModel = entityTypeService.Get(name, true, null); return(Read(entityTypeModel)); }
/// <summary> /// Reads the specified name. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public static EntityTypeCache Read( string name ) { if ( entityTypes.ContainsKey( name ) ) return Read( entityTypes[name] ); var entityTypeService = new Rock.Model.EntityTypeService(); var entityTypeModel = entityTypeService.Get( name, true, null ); return Read( entityTypeModel ); }
/// <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; } }