Exemple #1
0
        /// <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);
                }
            }
        }
Exemple #2
0
        /// <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);
                }
            }
        }
Exemple #3
0
        /// <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);
            }
        }
Exemple #4
0
 /// <summary>
 /// Removes groupType from cache
 /// </summary>
 /// <param name="id"></param>
 public static void Flush(int id)
 {
     FlushCache(GroupTypeCache.CacheKey(id));
 }
Exemple #5
0
 /// <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)));
 }
Exemple #6
0
 /// <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)));
 }
Exemple #7
0
        /// <summary>
        /// Removes groupType from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            FlushCache(GroupTypeCache.CacheKey(id));

            FlushCache("Rock:GroupType:All");
        }
Exemple #8
0
        /// <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));
        }