Пример #1
0
        /// <summary>
        /// Reads the specified GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public static EntityTypeCache Read(Guid guid)
        {
            ObjectCache cache    = MemoryCache.Default;
            object      cacheObj = cache[guid.ToString()];

            if (cacheObj != null)
            {
                return(Read((int)cacheObj));
            }
            else
            {
                var entityTypeService = new EntityTypeService();
                var entityTypeModel   = entityTypeService.Get(guid);
                if (entityTypeModel != null)
                {
                    var entityType = new EntityTypeCache(entityTypeModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(EntityTypeCache.CacheKey(entityType.Id), entityType, cachePolicy);
                    cache.Set(entityType.Guid.ToString(), entityType.Id, cachePolicy);

                    return(entityType);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #2
0
        /// <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);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Returns EntityType object from cache.  If entityBlockType 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
            {
                var entityTypeService = new EntityTypeService();
                var entityTypeModel   = entityTypeService.Get(id);
                if (entityTypeModel != null)
                {
                    entityType = new EntityTypeCache(entityTypeModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(cacheKey, entityType, cachePolicy);
                    cache.Set(entityType.Guid.ToString(), entityType.Id, cachePolicy);

                    return(entityType);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Removes entityType from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            FlushCache(EntityTypeCache.CacheKey(id));
            if (_entityTypes == null)
            {
                // shouldn't happen, but just in case
                _entityTypes = new ConcurrentDictionary <string, int>();
            }

            // rebuild the _entityTypes dictionary
            var _keepEntityTypes = _entityTypes.Where(a => a.Value != id);

            _entityTypes = new ConcurrentDictionary <string, int>(_keepEntityTypes);
        }
Пример #5
0
        /// <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);
            }
        }
Пример #6
0
        /// <summary>
        /// Removes entityType from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

            cache.Remove(EntityTypeCache.CacheKey(id));
        }
Пример #7
0
 /// <summary>
 /// Removes entityType from cache
 /// </summary>
 /// <param name="id"></param>
 public static void Flush(int id)
 {
     FlushCache(EntityTypeCache.CacheKey(id));
     _entityTypes = new ConcurrentDictionary <string, int>();
 }
Пример #8
0
 /// <summary>
 /// Reads the specified field type model.
 /// </summary>
 /// <param name="entityTypeModel">The field type model.</param>
 /// <returns></returns>
 public static EntityTypeCache Read(EntityType entityTypeModel)
 {
     return(GetOrAddExisting(EntityTypeCache.CacheKey(entityTypeModel.Id),
                             () => LoadByModel(entityTypeModel)));
 }
Пример #9
0
 /// <summary>
 /// Returns EntityType object from cache.  If entityBlockType 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 EntityTypeCache Read(int id, RockContext rockContext = null)
 {
     return(GetOrAddExisting(EntityTypeCache.CacheKey(id),
                             () => LoadById(id, rockContext)));
 }