当前位置: 首页>>代码示例>>C#>>正文


C# IDatabase.Get方法代码示例

本文整理汇总了C#中IDatabase.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.Get方法的具体用法?C# IDatabase.Get怎么用?C# IDatabase.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDatabase的用法示例。


在下文中一共展示了IDatabase.Get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetItem

        public bool GetItem(string key, out object value)
        {
            key.GuardAgainstNullOrEmpty(nameof(key));
            _database = _redis.GetDatabase();//connect only if arguments are valid to optimize resources 

            key = HashKey(key);
            var now = DateTimeOffset.Now;//local variables are thread safe should be out of sync lock
            
            try
            {
                value = _database.Get<CacheEntry>(key);
            } 
            catch (Exception e) 
            {
                value = null;
                OnCachingFailed(e);
            }

            if (value == null) return false;

            var entry = (CacheEntry)value;

            if (EntryExpired(entry, now))
            {
                InvalidateItem(key);
                value = null;
            }
            else
            {
                entry.LastAccess = now;
                value = entry.Value;
                // Update the entry in Redis to save the new LastAccess value.
                lock (_lock)
                {
                    try
                    {
                        _database.Set(key, entry);
                    }
                    catch (Exception e)
                    {
                        // Eventhough an error has occured, we will return true, because the retrieval of the entity was a success
                        OnCachingFailed(e);
                    }
                }
                return true;
            }

            return false;
        }
开发者ID:silentbobbert,项目名称:EFCache.Redis,代码行数:49,代码来源:RedisCache.cs

示例2: GetItem

        public bool GetItem(string key, out object value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            _database = _redis.GetDatabase();//connect only if arguments are valid to optimize resources 

            key = HashKey(key);
            var now = DateTimeOffset.Now;//local variables are thread safe should be out of sync lock
            
            lock (_lock)
            {
                try
                {
                    value = _database.Get<CacheEntry>(key);
                } 
                catch (Exception e) 
                {
                    value = null;
                    OnCachingFailed(e);
                }

                if (value == null) return false;

                var entry = (CacheEntry)value;

                if (EntryExpired(entry, now))
                {
                    InvalidateItem(key);
                    value = null;
                }
                else
                {
                    entry.LastAccess = now;
                    value = entry.Value;
                    return true;
                }
            }

            return false;
        }
开发者ID:GlenConway,项目名称:EFCache.Redis,代码行数:42,代码来源:RedisCache.cs

示例3: InvalidateItem

        public void InvalidateItem(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            _database = _redis.GetDatabase();

            key = HashKey(key);

            lock (_lock) 
            {
                try 
                {
                    var entry = _database.Get<CacheEntry>(key);

                    if (entry == null) return;

                    _database.KeyDelete(key);

                    foreach (var set in entry.EntitySets) {
                        _database.SetRemove(GetEntitySetKey(set), key);
                    }
                } 
                catch (Exception e) 
                {
                    OnCachingFailed(e);
                }
            }
        }
开发者ID:GlenConway,项目名称:EFCache.Redis,代码行数:30,代码来源:RedisCache.cs

示例4: InvalidateItem

        public void InvalidateItem(string key)
        {
            key.GuardAgainstNullOrEmpty(nameof(key));
            
            _database = _redis.GetDatabase();

            key = HashKey(key);

            lock (_lock) 
            {
                try 
                {
                    var entry = _database.Get<CacheEntry>(key);

                    if (entry == null) return;

                    _database.KeyDelete(key, CommandFlags.FireAndForget);

                    foreach (var set in entry.EntitySets) {
                        _database.SetRemove(AddCacheQualifier(set), key, CommandFlags.FireAndForget);
                    }
                } 
                catch (Exception e) 
                {
                    OnCachingFailed(e);
                }
            }
        }
开发者ID:silentbobbert,项目名称:EFCache.Redis,代码行数:28,代码来源:RedisCache.cs

示例5: MeasureGetTimeByRedis

 /// <summary>
 /// 測量讀取的時間
 /// </summary>
 /// <param name="cache"></param>
 private static void MeasureGetTimeByRedis(string cacheName, IDatabase cache)
 {
     System.Diagnostics.Stopwatch sh = new System.Diagnostics.Stopwatch();
     sh.Start();
     foreach (string key in redisManager.GetAllKeys())
     {
         if (key.StartsWith("OP-"))
         {
             object t = cache.Get(key);
         }
     }
     sh.Stop();
     Console.WriteLine(string.Format("CacheName:{0},Get-Milliseconds:{1}", cacheName, sh.ElapsedMilliseconds));
 }
开发者ID:kimx,项目名称:CacheMemoryMeasureLab,代码行数:18,代码来源:Program.cs


注:本文中的IDatabase.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。