Ejemplo n.º 1
0
        public RepoPaths GetRepoPaths(string currentPath, bool noCache)
        {
            if (string.IsNullOrWhiteSpace(currentPath))
            {
                throw new ArgumentException("Current path cannot be empty");
            }

            var       fixedCurPath = DWPSUtils.ForceTrailingSlash(currentPath);
            var       refCurPath   = "REF" + fixedCurPath;
            RepoPaths result       = null;

            if (!noCache)
            {
                result = RepoCache.Get <RepoPaths>(refCurPath);
            }

            if (result == null)
            {
                result = BuildRepoPaths(currentPath);
                RepoCache.Add(refCurPath, result, new TimeSpan(0, 10, 0), true);
            }

            result.IgnoreCache = noCache;

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     添加一个封包片
        /// </summary>
        /// <param name="key">唯一消息Id</param>
        /// <param name="message">封包片</param>
        /// <param name="timeSpan">过期时间</param>
        /// <param name="maxPacketCount">
        ///     最大封包片数
        ///     <para>* 第一次调用时设置此值,以后默认传-1即可。</para>
        /// </param>
        /// <returns>如果返回值不为null, 则证明已经拼接为一个完整的消息</returns>
        public T Add(int key, T message, TimeSpan timeSpan, int maxPacketCount = -1)
        {
            IReadonlyCacheStub <IMultiPacketStub <T> > stub = _caches.Get(key);

            if (stub != null)
            {
                return(stub.Cache.AddPacket(message) ? PickupMessage(stub.Cache) : default(T));
            }
            IMultiPacketStub <T> multiPacketStub = new MultiPacketStub <T>(key, maxPacketCount);

            multiPacketStub.AddPacket(message);
            _caches.Add(key, multiPacketStub, timeSpan);
            return(default(T));
        }
Ejemplo n.º 3
0
        public void GetRepoPaths_usesCacheIfAvailable()
        {
            var currentPath  = "C:\\testZZZ\\badYYY\\folderNNN";
            var cacheFolders = new RepoPaths {
                CurrentPath = currentPath
            };
            var cacheKey = "REF" + currentPath + "\\";

            _cacheManager.Get <RepoPaths>(cacheKey).Returns(cacheFolders);

            DWPSUtils._diskManager = _diskManager;

            var result = _gitUtils.GetRepoPaths(currentPath, false);

            _cacheManager.Received(1).Get <RepoPaths>(cacheKey);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.CurrentPath, currentPath);
            Assert.IsFalse(result.IgnoreCache);
        }
 public Achievement GetAchievement(object achievement, int value)
 {
     return(_achievmentsCacheContainer.Get(achievement, value));
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     获取一个具有指定key的缓存对象
 /// </summary>
 /// <param name="key">缓存对象Key</param>
 /// <returns>返回缓存对象</returns>
 public IReadonlyCacheStub <V> Get(K key)
 {
     //local cache first.
     return(_innerContainer.Get(key) ?? _proxy.Get(key));
 }