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

            if (cacheObj != null)
            {
                return(Read((int)cacheObj));
            }
            else
            {
                var LayoutService = new LayoutService();
                var LayoutModel   = LayoutService.Get(guid);
                if (LayoutModel != null)
                {
                    LayoutModel.LoadAttributes();
                    var Layout = new LayoutCache(LayoutModel);

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

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

            ObjectCache cache  = MemoryCache.Default;
            LayoutCache Layout = cache[cacheKey] as LayoutCache;

            if (Layout != null)
            {
                return(Layout);
            }
            else
            {
                var LayoutService = new LayoutService();
                var LayoutModel   = LayoutService.Get(id);
                if (LayoutModel != null)
                {
                    LayoutModel.LoadAttributes();
                    Layout = new LayoutCache(LayoutModel);

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

                    return(Layout);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds Layout model to cache, and returns cached object
        /// </summary>
        /// <param name="LayoutModel"></param>
        /// <returns></returns>
        public static LayoutCache Read(Layout LayoutModel)
        {
            string cacheKey = LayoutCache.CacheKey(LayoutModel.Id);

            ObjectCache cache  = MemoryCache.Default;
            LayoutCache Layout = cache[cacheKey] as LayoutCache;

            if (Layout != null)
            {
                return(Layout);
            }
            else
            {
                Layout = new LayoutCache(LayoutModel);

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

                return(Layout);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes Layout from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

            cache.Remove(LayoutCache.CacheKey(id));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Removes Layout from cache
 /// </summary>
 /// <param name="id"></param>
 public static void Flush(int id)
 {
     FlushCache(LayoutCache.CacheKey(id));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds Layout model to cache, and returns cached object
 /// </summary>
 /// <param name="LayoutModel"></param>
 /// <returns></returns>
 public static LayoutCache Read(Layout LayoutModel)
 {
     return(GetOrAddExisting(LayoutCache.CacheKey(LayoutModel.Id),
                             () => LoadByModel(LayoutModel)));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns Layout object from cache.  If Layout 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 LayoutCache Read(int id, RockContext rockContext = null)
 {
     return(GetOrAddExisting(LayoutCache.CacheKey(id),
                             () => LoadById(id, rockContext)));
 }