コード例 #1
0
        /// <summary>
        /// Flushes a cached page and it's parent page's list of child pages whenever a page is updated
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.ModelUpdatedEventArgs"/> instance containing the event data.</param>
        void Page_Updated(object sender, Rock.Data.ModelUpdatedEventArgs e)
        {
            // Get a reference to the updated page
            Rock.Model.Page page = e.Model as Rock.Model.Page;
            if (page != null)
            {
                // Check to see if the page being updated is cached
                System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default;
                if (cache.Contains(Rock.Web.Cache.PageCache.CacheKey(page.Id)))
                {
                    // Get the cached page
                    var cachedPage = Rock.Web.Cache.PageCache.Read(page.Id);

                    // if the parent page has changed, flush the old parent page's list of child pages
                    if (cachedPage.ParentPage != null && cachedPage.ParentPage.Id != page.ParentPageId)
                    {
                        cachedPage.ParentPage.FlushChildPages();
                    }

                    // Flush the updated page from cache
                    Rock.Web.Cache.PageCache.Flush(page.Id);
                }

                // Check to see if updated page has a parent
                if (page.ParentPageId.HasValue)
                {
                    // If the parent page is cached, flush it's list of child pages
                    if (cache.Contains(Rock.Web.Cache.PageCache.CacheKey(page.ParentPageId.Value)))
                    {
                        Rock.Web.Cache.PageCache.Read(page.ParentPageId.Value).FlushChildPages();
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 更新Cache
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="key"></param>
        public static bool UpdateStore <TValue>(this System.Runtime.Caching.ObjectCache cache,
                                                string key,
                                                TValue item)
        {
            bool result = false;

            if (string.IsNullOrEmpty(key))
            {
                return(result);
            }

            if (cache.Contains(key))       //檢查cache 是否有對應的資料
            {
                var instance = cache[key]; //取得該筆資料

                lock (instance)
                {
                    var instanceValue = ((Util.CacheExtensions.Container <TValue>)instance).Value; //取的該筆資料的值

                    foreach (var property in instanceValue.GetType().GetProperties())              //取得該筆資料的型別與內容物件
                    {
                        if (item.GetType().GetProperty(property.Name) != null)
                        {
                            property.SetValue(instanceValue, item.GetType().GetProperty(property.Name).GetValue(item));//更新內容
                        }
                    }
                    result = true;
                }
            }

            return(result);
        }
コード例 #3
0
        public ActionResult SubmitVideoComment(hypster_tv_DAL.videoComment p_comment, string video_guid)
        {
            hypster_tv_DAL.Hypster_Entities hyDB          = new hypster_tv_DAL.Hypster_Entities();
            hypster_tv_DAL.memberManagement memberManager = new hypster_tv_DAL.memberManagement();



            p_comment.comment = System.Text.RegularExpressions.Regex.Replace(p_comment.comment, @"<(.|\n)*?>", string.Empty);

            p_comment.ipAddress = IpAddress();
            p_comment.status    = (int)hypster_tv_DAL.newsCommentStatus.NoActive;
            p_comment.user_ID   = memberManager.getMemberByUserName(User.Identity.Name).id;
            p_comment.userName  = User.Identity.Name;
            p_comment.postDate  = DateTime.Now;


            hyDB.videoComments.AddObject(p_comment);
            hyDB.SaveChanges();



            //need to reset data cache (if exist)
            // this will allow to show new comment
            System.Runtime.Caching.ObjectCache i_chache = System.Runtime.Caching.MemoryCache.Default;
            if (i_chache["VideoComment_For_Tv_" + p_comment.videoClip_ID] != null)
            {
                i_chache.Remove("VideoComment_For_Tv_" + p_comment.videoClip_ID);
            }



            return(RedirectToAction("getVideo", "video", new { @video_id = video_guid }));
        }
コード例 #4
0
 public static TValue GetOrStore <TValue>(this System.Runtime.Caching.ObjectCache cache,
                                          string key,
                                          Func <TValue> create,
                                          TimeSpan slidingExpiration)
 {
     return(cache.GetOrStore(key, create, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration, slidingExpiration));
 }
コード例 #5
0
        /// <summary>
        /// Xóa ip action cache
        /// </summary>
        /// <param name="action">truyền vào tên action</param>
        /// <returns></returns>
        public static void IpActionDelete(string action)
        {
            string ip = IPAddressHelper.GetClientIP();

            System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default;
            cache.Remove("P" + ip.ToLower() + "_" + action);
        }
コード例 #6
0
        /// <summary>
        /// Đếm số lượt của hành động dựa trên tài khoản
        /// </summary>
        /// <param name="accountName">truyền vào tên tài khoản</param>
        /// <param name="action">truyền vào tên action</param>
        /// <returns></returns>
        public static int AccountActionCounter(string accountName, string action)
        {
            System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default;
            object cacheCounter = cache.Get("P" + accountName + "_" + action);

            return(Convert.ToInt32(cacheCounter));
        }
コード例 #7
0
 public static TValue GetOrStore <TValue>(this System.Runtime.Caching.ObjectCache cache,
                                          string key,
                                          Func <TValue> create,
                                          DateTime absoluteExpiration)
 {
     return(cache.GetOrStore(key, create, absoluteExpiration, System.Runtime.Caching.ObjectCache.NoSlidingExpiration));
 }
コード例 #8
0
ファイル: Open.cs プロジェクト: longshenwudu/LiteDB_LikeRedis
        public async static System.Threading.Tasks.Task <bool> Load(Env env)
        {
            try
            {
                var obj = env.Engine.FindById("ky", ID);
                //   await System.Threading.Tasks.Task.Delay(1000);
                if (obj != null)
                {
                    var o = BsonMapper.Global.ToObject <BL>(obj);

                    foreach (var a in o.v)
                    {
                        var obj_late = new System.Runtime.Caching.CacheItemPolicy();
                        obj_late.AbsoluteExpiration = o.off[a.Key];

                        obj_late.RemovedCallback = Exp.cb;
                        cache.Add(a.Key, a.Value, obj_late);

                        //   cache[a.Key] = a.Value;
                    }
                }
                if (cache == null)
                {
                    cache = System.Runtime.Caching.MemoryCache.Default;
                }
            }
            catch
            {
            }
            // await Back(env);
            return(true);
        }
コード例 #9
0
 public static TValue GetOrStoreAndNotRemove <TValue>(this System.Runtime.Caching.ObjectCache cache,
                                                      string key,
                                                      Func <TValue> create)
 {
     return(cache.GetOrStore(key, create,
                             System.Runtime.Caching.MemoryCache.InfiniteAbsoluteExpiration,
                             System.Runtime.Caching.MemoryCache.NoSlidingExpiration));
 }
コード例 #10
0
        /// <summary>
        /// Đếm số lượt của hành động dựa trên IP
        /// </summary>
        /// <param name="action">truyền vào tên action</param>
        /// <returns></returns>
        public static int IpActionCounter(string action)
        {
            string ip = IPAddressHelper.GetClientIP();

            System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default;
            object cacheCounter = cache.Get("P" + ip.ToLower() + "_" + action);

            return(Convert.ToInt32(cacheCounter));
        }
コード例 #11
0
        protected ObjectCache(
            String name, System.Runtime.Caching.ObjectCache innerCache, InMemoryPolicy policy)
        {
            this.name       = name;
            this.policy     = policy;
            this.innerCache = innerCache;

            this.synchronizer = CacheSynchronizer.CreateCacheSynchronizer(this, this.policy.SyncProvider);
        }
コード例 #12
0
ファイル: CapAdministration.cs プロジェクト: kf6kjg/f-stop
        public CapAdministration()
        {
            if (ConfigSingleton.NegativeCacheItemLifetime.TotalSeconds > 0)
            {
                _negativeCache     = System.Runtime.Caching.MemoryCache.Default;
                _negativeCacheLock = new ReaderWriterLockSlim();

                _negativeCachePolicy = new System.Runtime.Caching.CacheItemPolicy {
                    SlidingExpiration = ConfigSingleton.NegativeCacheItemLifetime,
                };
            }
        }
コード例 #13
0
ファイル: HubVuabai.cs プロジェクト: projectunitygame/Apigame
        private int CountPostFrequency(string action)
        {
            string ip = Utils.GetIp();

            System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default;
            object cacheCounter = cache.Get("Post" + ip.ToLower() + AccountSession.AccountName + "_" + action);

            if (cacheCounter == null)
            {
                return(0);
            }
            return(Convert.ToInt32(cacheCounter));
        }
コード例 #14
0
        //
        // GET: /getResult/

        //
        // GET: /getResult/

        public string Index()
        {
            string CURR_COMMAND = "";


            System.Runtime.Caching.ObjectCache i_chache = System.Runtime.Caching.MemoryCache.Default;
            if (i_chache["Member_Voice_"] != null)
            {
                CURR_COMMAND = (string)i_chache["Member_Voice_"];
            }

            return("C:" + CURR_COMMAND);
        }
コード例 #15
0
        /// <summary>
        /// Chỉ đếm số lượt trong cache
        /// </summary>
        /// <param name="action"></param>
        /// <returns>số lượt</returns>
        private int CheckStatusFrequency(string action)
        {
            string ip = IPAddressHelper.GetClientIP();

            System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default;
            object cacheCounter = cache.Get("@Post" + ip.ToLower() + AccountSession.AccountName + "_" + action);

            if (cacheCounter == null)
            {
                return(0);
            }
            return(Convert.ToInt32(cacheCounter));
        }
コード例 #16
0
        /// <summary>
        /// 移除Cache
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="key"></param>
        public static void RemoveStore(this System.Runtime.Caching.ObjectCache cache,
                                       string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            lock (cache)
            {
                if (cache.Contains(key))
                {
                    cache.Remove(key);
                }
            }
        }
コード例 #17
0
        /// <summary>
        /// Kiểm tra tài khoản thực hiện 1 hành động trong số giây (tự cộng số lượt mỗi lần gọi hàm check)
        /// </summary>
        /// <param name="accountName">Tên tài khoản</param>
        /// <param name="totalSecond">Số giây kiểm tra</param>
        /// <param name="action">tên hành động</param>
        /// <returns>số lượt gọi hành động</returns>
        public static int CheckAccountActionFrequency(string accountName, int totalSecond, string action)
        {
            System.Runtime.Caching.ObjectCache     cache  = System.Runtime.Caching.MemoryCache.Default;
            System.Runtime.Caching.CacheItemPolicy policy = new System.Runtime.Caching.CacheItemPolicy()
            {
                AbsoluteExpiration = DateTime.Now.AddSeconds(totalSecond)
            };
            object cacheCounter = cache.Get("P" + accountName + "_" + action);

            if (cacheCounter == null)
            {
                cache.Set("P" + accountName + "_" + action, 1, policy);
                return(0);
            }
            cache.Set("P" + accountName + "_" + action, Convert.ToInt32(cacheCounter) + 1, policy);
            return(Convert.ToInt32(cacheCounter));
        }
コード例 #18
0
        /// <summary>
        /// Thêm số lượt ăn theo tài khoản
        /// </summary>
        /// <param name="totalSecond"></param>
        /// <param name="action"></param>
        private void AddStatusFrequency(int totalSecond, string action)
        {
            string ip = IPAddressHelper.GetClientIP();

            System.Runtime.Caching.ObjectCache     cache  = System.Runtime.Caching.MemoryCache.Default;
            System.Runtime.Caching.CacheItemPolicy policy = new System.Runtime.Caching.CacheItemPolicy()
            {
                AbsoluteExpiration = DateTime.Now.AddSeconds(totalSecond)
            };
            object cacheCounter = cache.Get("@Post" + ip.ToLower() + AccountSession.AccountName + "_" + action);

            if (cacheCounter == null)
            {
                cache.Set("@Post" + ip.ToLower() + AccountSession.AccountName + "_" + action, 1, policy);
            }
            cache.Set("@Post" + ip.ToLower() + AccountSession.AccountName + "_" + action, Convert.ToInt32(cacheCounter) + 1, policy);
        }
コード例 #19
0
        /// <summary>
        /// 檢查快取位址是否有值,無則使用create查詢2
        /// </summary>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="cache"></param>
        /// <param name="key"></param>
        /// <param name="create"></param>
        /// <param name="absoluteExpiration"></param>
        /// <param name="slidingExpiration"></param>
        /// <returns></returns>
        public static TValue GetOrStore <TValue>(this System.Runtime.Caching.ObjectCache cache,
                                                 string key,
                                                 Func <string, TValue> create,
                                                 DateTimeOffset absoluteExpiration, TimeSpan slidingExpiration)
        {
            var instance = cache.GetOrStoreContainer <TValue>(key, absoluteExpiration, slidingExpiration);

            if (instance.Value == null)
            {
                lock (instance)
                    if (instance.Value == null)
                    {
                        instance.Value = create(key);
                    }
            }

            return(instance.Value);
        }
コード例 #20
0
ファイル: HubVuabai.cs プロジェクト: projectunitygame/Apigame
        private int CheckIpPostFrequency(int totalSecond, string action)
        {
            string ip = Utils.GetIp();

            System.Runtime.Caching.ObjectCache     cache  = System.Runtime.Caching.MemoryCache.Default;
            System.Runtime.Caching.CacheItemPolicy policy = new System.Runtime.Caching.CacheItemPolicy()
            {
                AbsoluteExpiration = DateTime.Now.AddSeconds(totalSecond)
            };
            object cacheCounter = cache.Get("Post" + ip.ToLower() + AccountSession.AccountName + "_" + action);

            if (cacheCounter == null)
            {
                cache.Set("Post" + ip.ToLower() + AccountSession.AccountName + "_" + action, 1, policy);
                return(0);
            }
            cache.Set("Post" + ip.ToLower() + AccountSession.AccountName + "_" + action, Convert.ToInt32(cacheCounter) + 1, policy);
            return(Convert.ToInt32(cacheCounter));
        }
コード例 #21
0
        /// <summary>
        /// Kiểm tra ip thực hiện 1 hành động trong số giây (tự cộng số lượt mỗi lần gọi hàm check)
        /// Không ăn theo tài khoản
        /// </summary>
        /// <param name="totalSecond">Số giây kiểm tra</param>
        /// <param name="action">tên hành động</param>
        /// <returns>số lượt gọi hành động</returns>
        public static int CheckIpPostFrequency(int totalSecond, string action)
        {
            string ip = IPAddressHelper.GetClientIP();

            System.Runtime.Caching.ObjectCache     cache  = System.Runtime.Caching.MemoryCache.Default;
            System.Runtime.Caching.CacheItemPolicy policy = new System.Runtime.Caching.CacheItemPolicy()
            {
                AbsoluteExpiration = DateTime.Now.AddSeconds(totalSecond)
            };
            object cacheCounter = cache.Get("P" + ip.ToLower() + "_" + action);

            if (cacheCounter == null)
            {
                cache.Set("P" + ip.ToLower() + "_" + action, 1, policy);
                return(0);
            }
            cache.Set("P" + ip.ToLower() + "_" + action, Convert.ToInt32(cacheCounter) + 1, policy);
            return(Convert.ToInt32(cacheCounter));
        }
コード例 #22
0
        protected ObjectCache(
            String name, System.Runtime.Caching.ObjectCache innerCache, InMemoryPolicy policy)
        {
            this.name       = name;
            this.policy     = policy;
            this.innerCache = innerCache;

            this.locks = !this.policy.DoNotLock
                ? new MultiLock(
                this.policy.NumberOfLocks ?? 50,
                this.policy.LockTimeoutMilliseconds != null && this.policy.LockTimeoutMilliseconds > 0
                        ? this.policy.LockTimeoutMilliseconds
                        : null,
                this.policy.DoThrowExceptionOnTimeout ?? true)
                : null;

            this.notiferName  = this.policy?.SyncProvider;
            this.synchronizer = CacheSynchronizer.CreateCacheSynchronizer(this, this.notiferName);
        }
コード例 #23
0
        /// <summary>
        /// Permite asignar el valor del token guardado en Caché en null para que en el próximo Request vuelva a ser consultado mediante la autenticacion de Azure.
        /// Esto es en un caso eventual en que el Token sea revocado o expirado de forma extraordinaria, pues el cache dura 50 minutos, y la vida del token es de 60
        /// por lo que no debería ocurrir, pero si ocurre, se consultará el token en el próximo request.
        /// </summary>
        /// <param name="statusCode"></param>
        internal void RemoveCacheIfStatusIsUnauthorized(HttpStatusCode statusCode)
        {
            try
            {
                if (statusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default;

                    if (cache != null)
                    {
                        if (cache.Get("AuthToken") != null)
                        {
                            cache.Remove("AuthToken");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #24
0
ファイル: StorageManager.cs プロジェクト: kf6kjg/WHIP-LRU
        /// <summary>
        /// Initializes a new instance of the <see cref="T:LibWhipLru.Cache.StorageManager"/> class.
        /// A zero or negative value for the negativeCacheItemLifetime results in the negative cache being disabled.
        /// </summary>
        /// <param name="localStorage">Local storage for assets.</param>
        /// <param name="negativeCacheItemLifetime">Negative cache item lifetime.</param>
        /// <param name="reader">Reader.</param>
        /// <param name="writer">Writer.</param>
        public StorageManager(
            AssetLocalStorageLmdbPartitionedLRU localStorage,
            TimeSpan negativeCacheItemLifetime,
            ChattelReader reader,
            ChattelWriter writer
            )
        {
            _localStorage = localStorage ?? throw new ArgumentNullException(nameof(localStorage));
            _assetReader  = reader ?? throw new ArgumentNullException(nameof(reader));
            _assetWriter  = writer ?? throw new ArgumentNullException(nameof(writer));

            if (negativeCacheItemLifetime.TotalSeconds > 0)
            {
                _negativeCache     = System.Runtime.Caching.MemoryCache.Default;
                _negativeCacheLock = new ReaderWriterLockSlim();

                _negativeCachePolicy = new System.Runtime.Caching.CacheItemPolicy {
                    SlidingExpiration = negativeCacheItemLifetime,
                };
            }
        }
コード例 #25
0
        /// <summary>
        /// 檢查是否存在快取位址,無則創建
        /// </summary>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="cache"></param>
        /// <param name="key"></param>
        /// <param name="absoluteExpiration"></param>
        /// <param name="slidingExpiration"></param>
        /// <returns></returns>
        private static Container <TValue> GetOrStoreContainer <TValue>(this System.Runtime.Caching.ObjectCache cache, string key, DateTimeOffset absoluteExpiration, TimeSpan slidingExpiration)
        {
            var instance = cache[key];

            if (instance == null)
            {
                lock (cache)
                {
                    instance = cache[key];
                    if (instance == null)
                    {
                        instance = new Container <TValue>();
                        System.Runtime.Caching.CacheItemPolicy policy = new System.Runtime.Caching.CacheItemPolicy();
                        policy.Priority           = System.Runtime.Caching.CacheItemPriority.Default;
                        policy.AbsoluteExpiration = absoluteExpiration;
                        // policy.SlidingExpiration = slidingExpiration;
                        policy.UpdateCallback = CacheItemRemoved;
                        cache.Set(key, instance, policy);
                    }
                }
            }

            return((Container <TValue>)instance);
        }
コード例 #26
0
        /// <summary>
        /// Flushes a cached page and it's parent page's list of child pages whenever a page is being deleted
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.ModelUpdatingEventArgs"/> instance containing the event data.</param>
        void Page_Deleting(object sender, Rock.Data.ModelUpdatingEventArgs e)
        {
            // Get a reference to the deleted page
            Rock.Model.Page page = e.Model as Rock.Model.Page;
            if (page != null)
            {
                // Check to see if the page being updated is cached
                System.Runtime.Caching.ObjectCache cache = System.Runtime.Caching.MemoryCache.Default;
                if (cache.Contains(Rock.Web.Cache.PageCache.CacheKey(page.Id)))
                {
                    // Get the cached page
                    var cachedPage = Rock.Web.Cache.PageCache.Read(page.Id);

                    // if the parent page is not null, flush parent page's list of child pages
                    if (cachedPage.ParentPage != null)
                    {
                        cachedPage.ParentPage.FlushChildPages();
                    }

                    // Flush the updated page from cache
                    Rock.Web.Cache.PageCache.Flush(page.Id);
                }
            }
        }
コード例 #27
0
ファイル: ObjectCache.cs プロジェクト: pub-comp/caching
        protected ObjectCache(
            String name, System.Runtime.Caching.ObjectCache innerCache, InMemoryPolicy policy)
        {
            this.name       = name;
            this.Policy     = policy;
            this.innerCache = innerCache;

            this.Locks = !this.Policy.DoNotLock
                ? new MultiLock(
                this.Policy.NumberOfLocks ?? 50,
                this.Policy.LockTimeoutMilliseconds != null && this.Policy.LockTimeoutMilliseconds > 0
                        ? this.Policy.LockTimeoutMilliseconds
                        : null,
                this.Policy.DoThrowExceptionOnTimeout ?? true)
                : null;

            if (this.Policy.OnSyncProviderFailure != null)
            {
                if (string.IsNullOrEmpty(this.Policy.SyncProvider))
                {
                    throw new ApplicationException($"{name}.OnSyncProviderFailure requires SyncProvider to be defined");
                }

                var cacheItemPolicy = ToRuntimePolicy(this.Policy);
                var syncProviderFailureCacheItemPolicy = ToRuntimePolicy(this.Policy.OnSyncProviderFailure);
                if (syncProviderFailureCacheItemPolicy.AbsoluteExpiration >= cacheItemPolicy.AbsoluteExpiration &&
                    syncProviderFailureCacheItemPolicy.SlidingExpiration >= cacheItemPolicy.SlidingExpiration)
                {
                    throw new ApplicationException($"{name}.OnSyncProviderFailure expiry policy needs to be more restrictive");
                }
            }

            this.notiferName  = this.Policy.SyncProvider;
            this.synchronizer = CacheSynchronizer.CreateCacheSynchronizer(this, this.notiferName,
                                                                          invalidateOnStateChange: this.Policy.OnSyncProviderFailure?.InvalidateOnProviderStateChange ?? false);
        }
コード例 #28
0
 public CacheEntryUpdateArguments(System.Runtime.Caching.ObjectCache source, System.Runtime.Caching.CacheEntryRemovedReason reason, string key, string regionName)
 {
 }
コード例 #29
0
 public CacheEntryRemovedArguments(System.Runtime.Caching.ObjectCache source, System.Runtime.Caching.CacheEntryRemovedReason reason, System.Runtime.Caching.CacheItem cacheItem)
 {
 }
コード例 #30
0
 public void ClearAll()
 {
     innerCache = new System.Runtime.Caching.MemoryCache(this.name);
 }