コード例 #1
0
        public bool Rename(string key, string newKey)
        {
            if (string.IsNullOrWhiteSpace(newKey))
            {
                throw new ArgumentNullException("newKey");
            }

#if !CORE_CLR
            var orignalValue = _innerCache.Remove(key);

            if (orignalValue != null)
            {
                _innerCache.Add(newKey, orignalValue, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration);
            }

            return(orignalValue != null);
#else
            object orignalValue;

            if (_innerCache.TryGetValue(key, out orignalValue))
            {
                _innerCache.Remove(key);
                _innerCache.Set(newKey, orignalValue, new MemoryCacheEntryOptions
                {
                    AbsoluteExpiration = DateTimeOffset.MaxValue
                });
            }

            return(orignalValue != null);
#endif
        }
コード例 #2
0
 public static void CacheEkle(string key, object value, int expireAsMinute)
 {
     if (_cache.Any(x => x.Key == key))
     {
         _cache.Remove(key);
     }
     _cache.Add(key, value, DateTimeOffset.Now.AddMinutes(expireAsMinute));
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: HePeng11/VS-GIT
        static void Main()
        {
            KeyValuePairs.Add(new System.Runtime.Caching.CacheItem("key1", "value1"), new System.Runtime.Caching.CacheItemPolicy());
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            BonusSkins.Register();
            SkinManager.EnableFormSkins();
            Application.Run(new MainForm());
        }
コード例 #4
0
        private void WriteToCache(String userAgent, DeviceInfo device)
        {
            var uaHash       = HashUserAgentString(userAgent);
            var _cachePolicy = new System.Runtime.Caching.CacheItemPolicy()
            {
                AbsoluteExpiration =
                    new DateTimeOffset(
                        DateTime.UtcNow.AddSeconds(_durationInSeconds))
            };

            _cache.Add(uaHash, device, _cachePolicy);
        }
コード例 #5
0
        public void Set(string key, object value, int expiresAsMinute)
        {
            System.Diagnostics.Contracts.Contract.Assert(!string.IsNullOrEmpty(key));
            System.Diagnostics.Contracts.Contract.Assert(value != null);
            System.Diagnostics.Contracts.Contract.Assert(expiresAsMinute > 0);

            if (IsExist(key))
            {
                Remove(key);
            }
            _cache.Add(key, value, DateTimeOffset.Now.AddMinutes(expiresAsMinute));
        }
コード例 #6
0
 public void Set(string key, object value, int expireAsMinute)
 {
     //tek islemde Exeption firlatmak
     //icine verilen kosul dogru ise OK degilse exeption fırlatir
     //Contract namespace altındaki assertion ları kullandık
     System.Diagnostics.Contracts.Contract.Assert(!string.IsNullOrEmpty(key));
     System.Diagnostics.Contracts.Contract.Assert(value != null);
     System.Diagnostics.Contracts.Contract.Assert(expireAsMinute > 0);
     if (IsExist(key))
     {
         Remove(key);
     }
     _cache.Add(key, value, DateTimeOffset.Now.AddMinutes(expireAsMinute));
 }
コード例 #7
0
ファイル: DBGuiInterface.cs プロジェクト: mlof/ED-IBE
        public T GetIniValue <T>(string initKey, string defaultValue = "", bool allowEmptyValue = true, bool rewriteOnBadCast = true, Boolean cached = true)
        {
            T retValue;

            if (cached)
            {
                if (m_SettingsCache.Contains(m_InitGroup + "|" + initKey))
                {
                    retValue = (T)m_SettingsCache.Get(m_InitGroup + "|" + initKey);
                }
                else
                {
                    retValue = m_DBCon.getIniValue <T>(m_InitGroup, initKey, defaultValue, allowEmptyValue, rewriteOnBadCast);
                    m_SettingsCache.Add(m_InitGroup + "|" + initKey, retValue, DateTime.UtcNow + new TimeSpan(0, 0, 1, 0));
                }
            }
            else
            {
                retValue = m_DBCon.getIniValue <T>(m_InitGroup, initKey, defaultValue, allowEmptyValue, rewriteOnBadCast);
                m_SettingsCache.Add(m_InitGroup + "|" + initKey, retValue, DateTime.UtcNow + new TimeSpan(0, 0, 1, 0));
            }

            return(retValue);
        }
コード例 #8
0
        public bool Rename(string key, string newKey)
        {
            if (string.IsNullOrWhiteSpace(newKey))
            {
                throw new ArgumentNullException("newKey");
            }

            var orignalValue = _innerCache.Remove(key);

            if (orignalValue != null)
            {
                _innerCache.Add(newKey, orignalValue, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration);
            }

            return(orignalValue != null);
        }
コード例 #9
0
ファイル: AppCache.cs プロジェクト: buweixiaomi/DydCert
        public AppCache()
        {
            System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default;
            List <AppModel> _cacheapps = mcache.Get(getcachename) as List <AppModel>;

            if (_cacheapps == null)
            {
                _cacheapps = new List <AppModel>();
                bool r = mcache.Add(getcachename, _cacheapps, new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes)));
                if (!r)
                {
                    throw new Exception("初始化缓存失败。");
                }
            }
            cacheapps = _cacheapps.CloneList();
        }
コード例 #10
0
        public void TestRunTimeCache()
        {
            var cache = new System.Runtime.Caching.MemoryCache("sys");

            cache.Add("user", new User {
                Name = "Foo"
            }, DateTime.Now.AddDays(1));

            User f = (User)cache.Get("user");

            Assert.Equal("Foo", f.Name);

            f.Name = "Bar";
            var b = (User)cache.Get("user");

            Assert.Equal("Bar", b.Name);
        }
コード例 #11
0
ファイル: CertCache.cs プロジェクト: buweixiaomi/DydCert
        public CertCache(ServiceCertType certtype)
        {
            this.certtype = certtype;
            System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default;
            List <CertCacheItem> _tempmanagecache     = mcache.Get(cachetypename) as List <CertCacheItem>;

            if (_tempmanagecache == null)
            {
                _tempmanagecache = new List <CertCacheItem>();
                bool r = mcache.Add(cachetypename, _tempmanagecache, new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes)));
                if (!r)
                {
                    throw new Exception("初始化缓存失败。");
                }
            }
            tempmanagecache = _tempmanagecache.CloneList();
        }
コード例 #12
0
ファイル: CertCache.cs プロジェクト: buweixiaomi/DydCert
        private void SetCertCahe()
        {
            System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default;
            if (tempmanagecache == null)
            {
                tempmanagecache = new List <CertCacheItem>();
            }
            if (mcache.Get(cachetypename) != null)
            {
                mcache.Remove(cachetypename);
            }

            bool r = mcache.Add(cachetypename, tempmanagecache.CloneList(), new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes)));

            if (!r)
            {
                mcache = null;
            }
        }
コード例 #13
0
ファイル: AppCache.cs プロジェクト: buweixiaomi/DydCert
        private void SetCache()
        {
            System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default;
            if (cacheapps == null)
            {
                cacheapps = new List <AppModel>();
            }
            if (mcache.Get(getcachename) != null)
            {
                mcache.Remove(getcachename);
            }

            bool r = mcache.Add(getcachename, cacheapps.CloneList(), new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes)));

            if (!r)
            {
                mcache = null;
            }
        }
コード例 #14
0
 /// <inheritdoc />
 public bool Add(string key, object value)
 {
     return(_memoryCache.Add(key, value, DateTimeOffset.MaxValue));
 }
コード例 #15
0
 public static void Set(string key, object o, int timeout)
 {
     System.Runtime.Caching.MemoryCache cache = System.Runtime.Caching.MemoryCache.Default;
     cache.Add(TransformKey(key), o, DateTime.Now.AddMinutes(timeout));
 }