Пример #1
0
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <param name="key">cache_key</param>
        /// <param name="something">content if null : remove cache</param>
        /// <returns></returns>
        private void SetCache(string key, object something = null)
        {
            if (key != null)
            {
                if (something == null)
                {
                    //删除缓存
                    DistributedCacheManager.Remove(key);
                }
                else
                {
                    //根据key获取缓存
                    var content = DistributedCacheManager.Get(key);
                    if (content != null)
                    {
                        //删除缓存
                        DistributedCacheManager.Remove(key);
                    }

                    //设置缓存
                    DistributedCacheManager.Set(key, something, 10);
                }
            }
            return;
        }
Пример #2
0
        public string GetRedisValue()
        {
            string str = "xzxzxzxxzx";

            DistributedCacheManager.Set("XXX", ByteConvertHelper.Object2Bytes(str), options: new Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1)
            });
            var val = DistributedCacheManager.GetByte("XXX");

            return((string)ByteConvertHelper.Bytes2Object(val));
        }