public void MemoryCacheManager_Should_Return_Count_When_Asked_So()
        {
            ICacheManager cacheManager = new MemoryCacheManager();

            cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy());
            cacheManager.Add("Test2", "Dit is de tweede waarde...", new CacheItemPolicy());
            cacheManager.Add("Test3", "Dit is de derde waarde...", new CacheItemPolicy());

            Assert.AreEqual(3, cacheManager.Count());
        }
        public void MemoryCacheManager_Should_Return_Last_Added_Value_To_Cache()
        {
            ICacheManager cacheManager = new MemoryCacheManager();

            cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy());
            cacheManager.Add("Test", "Dit is de tweede waarde...", new CacheItemPolicy());

            string value = cacheManager.Get <string>("Test");

            Assert.AreSame("Dit is de tweede waarde...", value);
        }
        public void MemoryCacheManager_Should_Contain_No_Values_When_Cleared()
        {
            ICacheManager cacheManager = new MemoryCacheManager();

            cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy());
            cacheManager.Add("Test2", "Dit is de tweede waarde...", new CacheItemPolicy());
            cacheManager.Add("Test3", "Dit is de derde waarde...", new CacheItemPolicy());

            cacheManager.Clear();

            Assert.AreEqual(0, cacheManager.Count());
        }
Exemplo n.º 4
0
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            //cache manager türetiliyor
            var cacheManager = new MemoryCacheManager();

            //metod ismi alınıyor
            var methodName = string.Format("{0}.{1}.{2}",
                                           args.Method.ReflectedType.Namespace,
                                           args.Method.ReflectedType.Name,
                                           args.Method.Name);

            //metod parametreleri alınıyor
            var arguments = args.Arguments.ToList();

            //cache key oluşturuluyor {MetodAdı.Parametreler}
            var key = string.Format("{0}({1})", methodName, string.Join(",", arguments.Select(x => x != null ? x.ToString() : "<Null>")));

            //metod cache de var ise oradan çağrılıyor
            if (cacheManager.IsAdd(key))
            {
                args.ReturnValue = cacheManager.Get <object>(key);
                return;
            }

            //metod çalıştırılıyor
            base.OnInvoke(args);

            //metod cache ekleniyor
            cacheManager.Add(key, args.ReturnValue, _dakika);
        }
        public void MemoryCacheManager_Should_Contain_Only_Values_That_Where_Not_To_Be_Deleted()
        {
            ICacheManager cacheManager = new MemoryCacheManager();

            cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy());
            cacheManager.Add("Test2", "Dit is de tweede waarde...", new CacheItemPolicy());
            cacheManager.Add("Test3", "Dit is de derde waarde...", new CacheItemPolicy());

            IList <string> collection = new List <string> {
                "Test",
                "Test3"
            };

            cacheManager.Remove(collection);

            Assert.AreEqual(1, cacheManager.Count());
        }
        public void MemoryCacheManager_Should_Return_Null_When_Item_From_Cache_Was_Removed_And_Afterwards_Requested()
        {
            ICacheManager cacheManager = new MemoryCacheManager();

            cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy());

            cacheManager.Remove("Test");

            Assert.IsFalse(cacheManager.Contains("Test"));
        }
        public void MemoryCacheManager_Should_Return_Value_When_Key_Available()
        {
            ICacheManager cacheManager = new MemoryCacheManager();

            cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy());

            string value = cacheManager.Get <string>("Test");

            Assert.IsNotNull(value);
        }
        public void MemoryCacheManager_Should_Return_Value_And_Be_Able_To_Change_Existing_Value()
        {
            ICacheManager cacheManager = new MemoryCacheManager();

            cacheManager.Add("Test", "Dit is de waarde...", new CacheItemPolicy());
            cacheManager.AddOrOverwrite("Test", "Dit is de echte waarde...", new CacheItemPolicy());

            string value = cacheManager.Get <string>("Test");

            Assert.AreSame("Dit is de echte waarde...", value);
        }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="result"></param>
 /// <param name="getFromCache"></param>
 /// <returns></returns>
 public static IEnumerable <T> AddToCache <T>(string key, IEnumerable <T> result, MemoryCacheManager cache, bool getFromCache = false, TimeSpan cacheInterval = default(TimeSpan))
 {
     if (getFromCache)
     {
         if (cacheInterval == default(TimeSpan))
         {
             cacheInterval = new TimeSpan(0, IntervalInMinutes, 0);
         }
         cache.Add <IEnumerable <T> >(key, result, DateTime.Now.Add(cacheInterval));
     }
     return(result);
 }
Exemplo n.º 10
0
        public IActionResult GetAll()
        {
            var list = _userService.GetAll();

            if (list != null)
            {
                var    cm       = new MemoryCacheManager();
                string cacheKey = "users";
                if (cm.Contains(cacheKey))
                {
                    cm.Remove(cacheKey);
                }
                cm.Add(cacheKey, list);
                return(Ok(list));
            }
            return(BadRequest());
        }
Exemplo n.º 11
0
        public List <Role> Find(string controller, string action)
        {
            List <Role>   list;
            var           cacheKey     = "DomurTech.Providers.RoleProvider.Find." + controller + "." + action;
            ICacheManager cacheManager = new MemoryCacheManager();

            if (!cacheManager.Exists(cacheKey))
            {
                list = GetValueFromDatabase(controller, action);
                cacheManager.Add(cacheKey, list);
            }
            else
            {
                return(cacheManager.Get <List <Role> >(cacheKey));
            }
            return(list);
        }
        public List <Language> GetAllLanguages()
        {
            List <Language> list;
            const string    cacheKey     = "DomurTech.Providers.LanguageProvider.GetAllLanguages";
            ICacheManager   cacheManager = new MemoryCacheManager();

            if (!cacheManager.Exists(cacheKey))
            {
                list = GetAllLanguagesFromDatabase();
                cacheManager.Add(cacheKey, list);
            }
            else
            {
                list = cacheManager.Get <List <Language> >(cacheKey);
            }
            return(list);
        }
Exemplo n.º 13
0
        public async Task TokenAuthorizeTest()
        {
            // Arrange
            var token = MockJwtTokens.GenerateJwtToken(ClaimsData.GetClaims());

            HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthenticationScheme, token);
            var cache = new MemoryCacheManager();

            cache.Add($"{CacheKeys.UserIdForClaim}=1", new List <string>()
            {
                "GetUsersQuery"
            });
            // Act
            var response = await HttpClient.GetAsync(RequestUri);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Exemplo n.º 14
0
        bool ICachingService.IsModulePrivate(AppModules module, int accountId)
        {
            string             cacheKey       = "datasharing" + accountId;
            IEnumerable <byte> privateModules = new List <byte>();

            if (!cacheManager.IsExists(cacheKey))
            {
                privateModules = accountRepository.GetPrivateModules(accountId);
                cacheManager.Add(cacheKey, privateModules, DateTimeOffset.MaxValue);
            }
            else
            {
                privateModules = cacheManager.Get <IEnumerable <byte> >(cacheKey);
            }
            return(privateModules.Contains((byte)module));
        }