Beispiel #1
0
        static void Main(string[] args)
        {
            MemoryCacheStore cacheStore = new MemoryCacheStore(
                MemoryCache.Default,
                new ConfigurationProvider(), new StoreReader(),
                new ConsoleLogger());

            string input;

            while ((input = Console.ReadLine()) != "q")
            {
                if (string.IsNullOrEmpty(input))
                {
                    break;
                }
                if (input.StartsWith("w:"))
                {
                    string value = input.Substring(2);
                    Write(cacheStore, value);
                }
                else if (input.StartsWith("r:"))
                {
                    string value = input.Substring(2);
                    Read(cacheStore, value);
                }
            }

            cacheStore.Dispose();
        }
        public void Memory_cache_set_full_with_max_size(string key, string key2)
        {
            //Arrange
            var expirationDate = DateTime.UtcNow.AddMinutes(15);
            var cache          = new MemoryCacheStore(1);
            var context        = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(key, context, expirationDate);
            cache.Set(key2, context, expirationDate);

            var response  = cache.Get(key);
            var response2 = cache.Get(key2);

            //Assert
            Assert.Equal(context.Response.ContentType, response.ContentType);
            Assert.Equal(context.Response.StatusCode, response.StatusCode);
            Assert.Equal(expirationDate, response.Expiration);
            Assert.Equal(context.Response.Contents.ConvertStream(), response.Contents.ConvertStream());
            Assert.Null(response2);
        }
Beispiel #3
0
        private static void Write(MemoryCacheStore cacheStore, string value)
        {
            var key = GetKey(value);

            cacheStore.Write(new List <DocItem>()
            {
                new DocItem(key),
            });
        }
        public void Memory_cache_empty_get()
        {
            //Arrange
            var cache   = new MemoryCacheStore();
            var context = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(string.Empty, context, DateTime.UtcNow.AddMinutes(1));
            var response = cache.Get(string.Empty);

            //Assert
            Assert.Null(response);
        }
        public void Memory_cache_set_get_expired(string key)
        {
            //Arrange
            var expiredDate = DateTime.UtcNow;
            var cache       = new MemoryCacheStore();
            var context     = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(key, context, expiredDate);
            var response = cache.Get(key);

            //Assert
            Assert.Null(response);
            Assert.NotNull(context.Response);
        }
        public void Memory_cache_set_get()
        {
            //Arrange
            var expirationDate = DateTime.UtcNow.AddMinutes(15);
            var cache          = new MemoryCacheStore();
            var context        = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(TEST_KEY_1, context, expirationDate);
            var response = cache.Get(TEST_KEY_1);

            //Assert
            Assert.Equal(context.Response.ContentType, response.ContentType);
            Assert.Equal(context.Response.StatusCode, response.StatusCode);
            Assert.Equal(expirationDate, response.Expiration);
            Assert.Equal(context.Response.Contents.ConvertStream(), response.Contents.ConvertStream());
        }
        public void Memory_cache_set_remove_get(string key)
        {
            //Arrange
            var expirationDate = DateTime.UtcNow.AddMinutes(15);
            var cache          = new MemoryCacheStore();
            var context        = new NancyContext()
            {
                Response = new FakeResponse()
                {
                }
            };

            //Act
            cache.Set(key, context, expirationDate);

            cache.Remove(key);

            var response = cache.Get(key);

            //Assert
            Assert.Null(response);
            Assert.NotNull(context.Response);
        }
Beispiel #8
0
 public CacheUsage(MemoryCacheStore store)
     : base(store, helper)
 {
 }
Beispiel #9
0
		public CacheUsage (MemoryCacheStore store)
			: base (store, helper)
		{
		}
Beispiel #10
0
 private static void Read(MemoryCacheStore cacheStore, string value)
 {
     var key     = GetKey(value);
     var docItem = cacheStore[key];
 }