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

            if (cacheObj != null)
            {
                return(Read((int)cacheObj));
            }
            else
            {
                var siteService = new SiteService();
                var siteModel   = siteService.Get(guid);
                if (siteModel != null)
                {
                    siteModel.LoadAttributes();
                    var site = new SiteCache(siteModel);

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

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

            ObjectCache cache = MemoryCache.Default;
            SiteCache   site  = cache[cacheKey] as SiteCache;

            if (site != null)
            {
                return(site);
            }
            else
            {
                var siteService = new SiteService();
                var siteModel   = siteService.Get(id);
                if (siteModel != null)
                {
                    siteModel.LoadAttributes();
                    site = new SiteCache(siteModel);

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

                    return(site);
                }
                else
                {
                    return(null);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Adds Site model to cache, and returns cached object
        /// </summary>
        /// <param name="siteModel"></param>
        /// <returns></returns>
        public static SiteCache Read(Site siteModel)
        {
            string cacheKey = SiteCache.CacheKey(siteModel.Id);

            ObjectCache cache = MemoryCache.Default;
            SiteCache   site  = cache[cacheKey] as SiteCache;

            if (site != null)
            {
                return(site);
            }
            else
            {
                site = new SiteCache(siteModel);

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

                return(site);
            }
        }
Example #4
0
        /// <summary>
        /// Returns Site object from cache.  If site does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static SiteCache Read(int id)
        {
            string cacheKey = SiteCache.CacheKey(id);

            ObjectCache cache = MemoryCache.Default;
            SiteCache   site  = cache[cacheKey] as SiteCache;

            if (site != null)
            {
                return(site);
            }
            else
            {
                Rock.Model.SiteService siteService = new Model.SiteService();
                Rock.Model.Site        siteModel   = siteService.Get(id);
                if (siteModel != null)
                {
                    site = new SiteCache(siteModel);

                    siteModel.LoadAttributes();

                    foreach (var attribute in siteModel.Attributes)
                    {
                        site.AttributeIds.Add(attribute.Value.Id);
                    }

                    site.AttributeValues = siteModel.AttributeValues;

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

                    return(site);
                }
                else
                {
                    return(null);
                }
            }
        }
Example #5
0
 /// <summary>
 /// Removes site from cache
 /// </summary>
 /// <param name="id"></param>
 public static void Flush(int id)
 {
     FlushCache(SiteCache.CacheKey(id));
     _siteDomains = new ConcurrentDictionary <string, int>();
 }
Example #6
0
 /// <summary>
 /// Adds Site model to cache, and returns cached object
 /// </summary>
 /// <param name="siteModel"></param>
 /// <returns></returns>
 public static SiteCache Read(Site siteModel)
 {
     return(GetOrAddExisting(SiteCache.CacheKey(siteModel.Id),
                             () => LoadByModel(siteModel)));
 }
Example #7
0
 /// <summary>
 /// Returns Site object from cache.  If site 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 SiteCache Read(int id, RockContext rockContext = null)
 {
     return(GetOrAddExisting(SiteCache.CacheKey(id),
                             () => LoadById(id, rockContext)));
 }
Example #8
0
        /// <summary>
        /// Removes site from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

            cache.Remove(SiteCache.CacheKey(id));
        }