Ejemplo n.º 1
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));
        }