Пример #1
0
        private static ICacheCreator CreateCache(string name)
        {
            ICacheCreator creator = PlugInFactoryManager.CreateInstance <ICacheCreator>(
                CacheCreatorPlugInFactory.REG_NAME, name);

            return(creator);
        }
Пример #2
0
        public object GetCacheItem(string cacheName, string key,
                                   params object[] args)
        {
            TkDebug.AssertArgumentNullOrEmpty(cacheName, "cacheName", this);
            TkDebug.AssertArgumentNullOrEmpty(key, "key", this);

            ICache cache = GetCache(cacheName);
            BaseCacheItemCreator creator = PlugInFactoryManager.CreateInstance <BaseCacheItemCreator>(
                CacheItemCreatorPlugInFactory.REG_NAME, cacheName);

            TkDebug.AssertNotNull(creator, $"{cacheName}不存在", this);

            if (cache == null)
            {
                ICacheCreator cacheCreator = creator.CacheCreator;
                if (cacheCreator == null)
                {
                    cacheCreator = creator.SupportDistributed ? DefaultDistributedCreator : DefaultCreator;
                }
                cache = cacheCreator.CreateCache(cacheName);
                CacheLock.WriteLockAction(() =>
                {
                    if (!fCaches.ContainsKey(cacheName))
                    {
                        fCaches.Add(cacheName, cache);
                        return(true);
                    }
                    return(false);
                });
            }
            return(cache.GetItem(creator.TransformCacheKey(key), creator, args));
        }
Пример #3
0
        protected BaseCacheItemCreator(ICacheCreator cacheCreator)
        {
            TkDebug.AssertArgumentNull(cacheCreator, "cacheCreator", null);

            CacheCreator = cacheCreator;
            Initialize();
        }
		public MemoryCache(string name, ICacheCreator creator)
		{
			if(string.IsNullOrWhiteSpace(name))
				throw new ArgumentNullException("name");

			_innerCache = new System.Runtime.Caching.MemoryCache(name);
			_creator = creator;
		}
Пример #5
0
        public MemoryCache(string name, ICacheCreator creator)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            _innerCache = new System.Runtime.Caching.MemoryCache(name);
            _creator    = creator;
        }
Пример #6
0
        public MemoryCache(string name, ICacheCreator creator)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            _creator = creator;
            _name    = name;

#if !CORE_CLR
            _innerCache = new System.Runtime.Caching.MemoryCache(name);
#else
            _innerCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(new MemoryCacheOptions());
#endif
        }
Пример #7
0
 protected DistributeCacheItemCreator(ICacheCreator cacheCreator) : base(cacheCreator)
 {
 }