CacheKey() 개인적인 정적인 메소드

Caches the key.
private static CacheKey ( int id ) : string
id int The id.
리턴 string
예제 #1
0
        /// <summary>
        /// Returns Role object from cache.  If role does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static Role Read(int id)
        {
            string cacheKey = Role.CacheKey(id);

            ObjectCache cache = Rock.Web.Cache.RockMemoryCache.Default;
            Role        role  = cache[cacheKey] as Role;

            if (role != null)
            {
                return(role);
            }
            else
            {
                using (var rockContext = new RockContext())
                {
                    Rock.Model.GroupService groupService = new Rock.Model.GroupService(rockContext);
                    Rock.Model.Group        groupModel   = groupService.Get(id);

                    if (groupModel != null && groupModel.IsSecurityRole == true)
                    {
                        role       = new Role();
                        role.Id    = groupModel.Id;
                        role.Name  = groupModel.Name;
                        role.Users = new List <string>();
                        role.IsSecurityTypeGroup = groupModel.GroupType.Guid.Equals(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid());

                        foreach (Rock.Model.GroupMember member in groupModel.Members)
                        {
                            role.Users.Add(member.Person.Guid.ToString());
                        }

                        cache.Set(cacheKey, role, new CacheItemPolicy());

                        return(role);
                    }
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Returns Role object from cache.  If role does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static Role Read(int id)
        {
            string cacheKey = Role.CacheKey(id);

            ObjectCache cache = MemoryCache.Default;
            Role        role  = cache[cacheKey] as Role;

            if (role != null)
            {
                return(role);
            }
            else
            {
                Rock.Model.GroupService groupService = new Rock.Model.GroupService();
                Rock.Model.Group        groupModel   = groupService.Get(id);

                if (groupModel != null && groupModel.IsSecurityRole == true)
                {
                    role       = new Role();
                    role.Id    = groupModel.Id;
                    role.Name  = groupModel.Name;
                    role.Users = new List <string>();

                    foreach (Rock.Model.GroupMember member in groupModel.Members)
                    {
                        role.Users.Add(member.Person.Guid.ToString());
                    }

                    cache.Set(cacheKey, role, new CacheItemPolicy());

                    return(role);
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Removes role from cache
        /// </summary>
        /// <param name="id">The id.</param>
        public static void Flush(int id)
        {
            ObjectCache cache = Rock.Web.Cache.RockMemoryCache.Default;

            cache.Remove(Role.CacheKey(id));
        }
예제 #4
0
 /// <summary>
 /// Returns Role object from cache.  If role does not already exist in cache, it
 /// will be read and added to cache
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns></returns>
 public static Role Read(int id)
 {
     return(GetOrAddExisting(Role.CacheKey(id),
                             () => LoadById(id)));
 }