Exemple #1
0
        /// <summary>
        /// 注入本地内存缓存服务
        /// </summary>
        /// <param name="cissyConfigBuilder"></param>
        /// <param name="MemoryCacheOptions"></param>
        /// <returns></returns>
        public static CissyConfigBuilder AddLocalMemoryCache(this CissyConfigBuilder cissyConfigBuilder, Microsoft.Extensions.Caching.Memory.MemoryCacheOptions MemoryCacheOptions = default)
        {
            LocalMemoryCache cache = new LocalMemoryCache();

            cache.Init(MemoryCacheOptions);

            cissyConfigBuilder.ServiceCollection.AddSingleton(typeof(ILocalMemoryCache), cache);
            return(cissyConfigBuilder);
        }
Exemple #2
0
        static private Task TestNonAsyncCacheAsync()
        {
            using (var localCache = new LocalMemoryCache())
            {
                var cacheKey = "mykey";
                var value    = localCache.Get(cacheKey, (name, args) =>
                {
                    return(new CacheDataInfo <string>
                    {
                        KeepAlive = TimeSpan.FromHours(4),
                        NewCacheData = "Ross"
                    });
                });

                Console.WriteLine(value);
            }

            return(Task.CompletedTask);
        }