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


C# IDatabase.Set方法代码示例

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


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

示例1: PutItem

        public void PutItem(string key, object value, IEnumerable<string> dependentEntitySets, TimeSpan slidingExpiration, DateTimeOffset absoluteExpiration)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (dependentEntitySets == null)
            {
                throw new ArgumentNullException("dependentEntitySets");
            }
            _database = _redis.GetDatabase();
            
            key = HashKey(key);
            var entitySets = dependentEntitySets.ToArray();

            lock (_lock)
            {
                try 
                {
                    _database.Set(key, new CacheEntry(value, entitySets, slidingExpiration, absoluteExpiration));
                    foreach (var entitySet in entitySets) {
                        _database.SetAdd(GetEntitySetKey(entitySet), key);
                    }
                } 
                catch (Exception e) 
                {
                    OnCachingFailed(e);
                }
            }
        }
开发者ID:GlenConway,项目名称:EFCache.Redis,代码行数:31,代码来源:RedisCache.cs

示例2: PutItem

        public void PutItem(string key, object value, IEnumerable<string> dependentEntitySets, TimeSpan slidingExpiration, DateTimeOffset absoluteExpiration)
        {
            key.GuardAgainstNullOrEmpty(nameof(key));
            // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null
            dependentEntitySets.GuardAgainstNull(nameof(dependentEntitySets));
           
            _database = _redis.GetDatabase();
            
            key = HashKey(key);
            // ReSharper disable once PossibleMultipleEnumeration - the guard clause should not enumerate, its just checking the reference is not null
            var entitySets = dependentEntitySets.ToArray();

            lock (_lock)
            {
                try 
                {
                    foreach (var entitySet in entitySets)
                    {
                        _database.SetAdd(AddCacheQualifier(entitySet), key, CommandFlags.FireAndForget);
                    }

                    _database.Set(key, new CacheEntry(value, entitySets, slidingExpiration, absoluteExpiration));
                } 
                catch (Exception e) 
                {
                    OnCachingFailed(e);
                }
            }
        }
开发者ID:silentbobbert,项目名称:EFCache.Redis,代码行数:29,代码来源:RedisCache.cs

示例3: 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

示例4: MeasureSetMemoryAndTimeByRedis

        /// <summary>
        /// 測量寫入的時間及記憶體
        /// </summary>
        /// <param name="cache"></param>
        private static void MeasureSetMemoryAndTimeByRedis(string cacheName, IDatabase cache)
        {
            System.Diagnostics.Stopwatch sh = new System.Diagnostics.Stopwatch();

            sh.Start();
            MemWatch mw = new MemWatch(true);
            List<UserMenuInfo> menus = GetTestData();
            Console.WriteLine(string.Format("CacheName:{0},MemorySizeChangeInKB:{1}", cacheName, mw.MemorySizeChangeInKB));
            mw.Start();
            foreach (var menu in menus)
            {
                cache.Set("OP-" + menu.PRG_NO, menu, TimeSpan.FromDays(1));
            }
            mw.Stop();
            Console.WriteLine(string.Format("CacheName:{0},MemorySizeChangeInKB:{1}", cacheName, mw.MemorySizeChangeInKB));
            sh.Stop();
            Console.WriteLine(string.Format("CacheName:{0},Set-Milliseconds:{1}", cacheName, sh.ElapsedMilliseconds));
        }
开发者ID:kimx,项目名称:CacheMemoryMeasureLab,代码行数:22,代码来源:Program.cs


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