Exemple #1
0
        public void AddNotOutOfRange_MustAllInCache()
        {
            var lru = new LruCacher <int, string>(2);

            lru.Add(1, "a");
            lru.Add(2, "b");
            var dic = lru.Datas;

            Assert.AreEqual(lru.Get(1), dic[1]);
            Assert.AreEqual(lru.Get(2), dic[2]);
            Assert.IsNotNull(lru.SyncRoot);
            Assert.AreEqual(2, lru.Max);
            var aval = lru.Get(1);

            Assert.AreEqual("a", aval);
            var bval = lru.Get(2);

            Assert.AreEqual("b", bval);
            var nval = lru.Get(-1);

            Assert.IsNull(nval);
            var res = lru.TryGetValue(1, out var v);

            Assert.IsTrue(res);
            Assert.AreEqual("a", v);
            res = lru.TryGetValue(888, out v);
            Assert.IsFalse(res);
            Assert.IsNull(v);
        }
Exemple #2
0
        public void AddExistsValue_MustPutItHead()
        {
            var lru = new LruCacher <int, string>(2);

            lru.Add(1, "a");
            lru.Add(2, "b");

            lru.Add(1, "c");
            lru.Add(3, "q");
            Assert.AreEqual("c", lru.Get(1));
            Assert.IsNull(lru.Get(2));
        }
Exemple #3
0
        public void AddOutOfRange_MustRemovedPrevItem()
        {
            var lru = new LruCacher <int, string>(2);

            Assert.AreEqual(2, lru.Max);
            lru.Add(1, "a");
            lru.Add(2, "b");
            lru.Add(3, "c");

            var val1 = lru.Get(1);

            Assert.IsNull(val1);
            Assert.AreEqual(2, lru.Count);
            lru.Get(3);
            lru.Get(2);
            lru.Add(4, "d");
            var val2 = lru.Get(3);

            Assert.IsNull(val2);
            var val3 = lru.Get(2);

            Assert.AreEqual("b", val3);
        }
Exemple #4
0
        private async Task <BlobClient> GetFileAsync(string address)
        {
            //var hash = ContainerName + Md5Helper.MakeMd5(address).ToLower();
            var client = blobServiceClient.GetBlobContainerClient(ContainerName);

            if (!createdCacher.Get(ContainerName))
            {
                await client.CreateIfNotExistsAsync();

                createdCacher.Add(ContainerName, true);
            }
            var key = GetFileName(address);

            return(client.GetBlobClient(key));
        }
Exemple #5
0
        public void GetOrAdd_ValueMustBeAddOrGet()
        {
            var modify = 0;
            var lru    = new LruCacher <int, string>(2);
            var v      = lru.GetOrAdd(1, () =>
            {
                modify++;
                return("a");
            });
            var val = lru.Get(1);

            Assert.AreEqual("a", v);
            Assert.AreEqual("a", val);
            Assert.AreEqual(1, lru.Count);
            v = lru.GetOrAdd(1, () =>
            {
                modify++;
                return("a");
            });
            Assert.AreEqual(1, lru.Count);
            Assert.AreEqual("a", v);
        }