static void Main(string[] args) { Person p1 = new Person { Id = 1, Age = 10, Name = "" }; Person p2 = new Person { Id = 2, Age = 11, Name = "" }; Person p3 = new Person { Id = 3, Age = 12, Name = "" }; ICachingService <int, Person> cache = new CachingService <int, Person>(); //ICachingService<int, Person> cache = new CachingService<int, Person>(new LRUAlgorithm<int, Person>()); //ICachingService<int, Person> cache = new CachingService<int, Person>(new MRUAlgorithm<int, Person>()); cache.Add(1, p1); cache.Add(2, p2); cache.Add(3, p3); var rez = cache.Get(2); ICachingService <int, Person2> cache2 = new CachingService <int, Person2>(); Person2 p4 = new Person2 { Id = 1, Age = 13, Name = "" }; cache2.Add(1, p4); var rez2 = cache.Get(1); var rez3 = cache2.Get(1); }
public void RemovedItemCannotBeRetrievedFromCache() { var sut = new CachingService(); sut.Add(TestKey, new object()); Assert.NotNull(sut.Get <object>(TestKey)); sut.Remove(TestKey); Assert.Null(sut.Get <object>(TestKey)); }
public void Get_WillReturnNullIfNoCacheBasedOnThatKey() { // arrange var key = "testKey"; // act var result = _cachingService.Get(key); // assert Assert.AreEqual(null, result); }
public ActionResult nationalRanking(int?id) { if (!id.HasValue || !(id >= 2009 && id <= KSU.maxPlayerSeason)) { return(RedirectToAction("national-ranking", "nationalranking", new { id = KSU.maxPlayerSeason })); } int year = id.Value; // Get Dates List <double> pollDates = _dataBL.GetRankingDates(year); double maxDate = pollDates.Max(); var cacheService = new CachingService(); var cacheMaxDate = cacheService.Get <double>("chart" + year + "maxdate"); if (cacheMaxDate < maxDate) { createChart(year, maxDate, pollDates); } NationalRankingModel ranking = new NationalRankingModel(new GameListModel(_gameBL.GamesBySeason(year)), year, cacheService.Get <string>("chart" + year + "imagemap")); return(View(ranking)); }
public KerberosReceiverSecurityToken ReadFromCache(string contextUsername) { IAppCache appCache = new CachingService(); KerberosReceiverSecurityToken token = appCache.Get <KerberosReceiverSecurityToken>(contextUsername.ToLower()); return(token); }
public void AddThenGetReturnsCachedObject() { var sut = new CachingService(); sut.Add(TestKey, "testObject"); Assert.AreEqual("testObject", sut.Get <string>(TestKey)); }
internal FileRecord Get(Guid id) { if (id == Guid.Empty) { return(null); } string cachingKey = "fsFileRecord:" + id.ToString(); FileRecord fileRecord; fileRecord = _cachingService.Get <FileRecord>(cachingKey); if (fileRecord != null) { return(fileRecord); } List <CommandParameter> parameterList = new List <CommandParameter>(); parameterList.Add(new CommandParameter("@id", id)); List <FileRecord> fileRecordList = _dataBase.Select <FileRecord>("SELECT * FROM [File] Where Id = @id", parameterList); if (fileRecordList.Count == 0) { return(null); } fileRecord = fileRecordList[0]; _cachingService.Set(cachingKey, fileRecord, _cachingExpiresIn); return(fileRecord); }
public void AddWithOffsetReturnsCachedItem() { var sut = new CachingService(); sut.Add(TestKey, "testObject", DateTimeOffset.Now.AddSeconds(1)); Assert.AreEqual("testObject", sut.Get <string>(TestKey)); }
public void AddWithPolicyReturnsCachedItem() { var sut = new CachingService(); sut.Add(TestKey, "testObject", new CacheItemPolicy()); Assert.AreEqual("testObject", sut.Get <string>(TestKey)); }
public void GetNullKeyThrowsException() { var sut = new CachingService(); Action act = () => sut.Get <object>(null); act.ShouldThrow <ArgumentNullException>(); }
public void AddWithSlidingReturnsCachedItem() { var sut = new CachingService(); sut.Add(TestKey, "testObject", new TimeSpan(5000)); Assert.AreEqual("testObject", sut.Get <string>(TestKey)); }
public void Get_ReturnsNullWhenItemNotCached() { CachingService cachingService = new CachingService(); string response = cachingService.Get("abc") as string; Assert.Null(response); }
public void GetEmptyKeyThrowsException() { var sut = new CachingService(); Action act = () => sut.Get <object>(""); act.ShouldThrow <ArgumentOutOfRangeException>(); }
public ActionResult ResetPwd() { MemberResetPasswordArgs args = RequestArgs <MemberResetPasswordArgs>(); if (args == null) { return(FailedResult("参数无效。")); } //校验验证码 string code = _cachingService.Get(args.mobilephone + "ValidationCode"); if (string.IsNullOrEmpty(code) == true) { return(FailedResult("验证码已失效。")); } if (code.Equals(args.code) == false) { return(FailedResult("错误的验证码。")); } Member member = _memberManager.GetMemberByMobilePhone(args.mobilephone); if (member == null) { return(FailedResult("指定的会员不存在!")); } NormalResult result = _memberManager.UpdateMemberPassword(member.id, IOHelper.GetMD5HashFromString(args.password)); return(ApiResult(result.Successful, "修改密码成功。")); }
public void GetWithClassTypeParamReturnsType() { var sut = new CachingService(); var cached = new EventArgs(); sut.Add(TestKey, cached); Assert.AreEqual(cached, sut.Get <EventArgs>(TestKey)); }
public void AddWithOffsetThatExpiresReturnsNull() { var sut = new CachingService(); sut.Add(TestKey, "testObject", DateTimeOffset.Now.AddSeconds(1)); Thread.Sleep(1500); Assert.IsNull(sut.Get <string>(TestKey)); }
public void AddWithSlidingThatExpiresReturnsNull() { var sut = new CachingService(); sut.Add(TestKey, "testObject", new TimeSpan(750)); Thread.Sleep(1500); Assert.IsNull(sut.Get <string>(TestKey)); }
public void GetWithWrongStructTypeParamReturnsNull() { var sut = new CachingService(); var cached = new DateTime(); sut.Add(TestKey, cached); Assert.AreEqual(new TimeSpan(), sut.Get <TimeSpan>(TestKey)); }
public void GetWithNullableIntRetunsCachedNonNullableInt() { var sut = new CachingService(); const int expected = 123; sut.Add(TestKey, expected); Assert.AreEqual(expected, sut.Get <int?>(TestKey)); }
public void GetWithStructTypeParamReturnsType() { var sut = new CachingService(); var cached = new DateTime(2000, 1, 1); sut.Add(TestKey, cached); Assert.AreEqual(cached, sut.Get <DateTime>(TestKey)); }
public void GetWithValueTypeParamReturnsType() { var sut = new CachingService(); const int cached = 3; sut.Add(TestKey, cached); Assert.AreEqual(3, sut.Get <int>(TestKey)); }
public void GetWithWrongClassTypeParamReturnsNull() { var sut = new CachingService(); var cached = new EventArgs(); sut.Add(TestKey, cached); Assert.IsNull(sut.Get <ArgumentNullException>(TestKey)); }
public void GetCachedNullableStructTypeParamReturnsType() { var sut = new CachingService(); DateTime?cached = new DateTime(); sut.Add(TestKey, cached); Assert.AreEqual(cached.Value, sut.Get <DateTime>(TestKey)); }
public void CachingService_MemoryCacheProvider_ShouldCache() { var key = nameof(CachingService_MemoryCacheProvider_ShouldCache); Assert.IsNull(_cacheService.Get <TestObject>(key)); _cacheService.Add(key, new TestObject { Name = "Test", Value = 1024 }); var val = _cacheService.Get <TestObject>(key); Assert.NotNull(val); Assert.AreEqual("Test", val.Name); Assert.AreEqual(1024, val.Value); // cacheService.Remove(key); }
public void Get_ReturnsNullWhenItemInvalidated() { CachingService cachingService = new CachingService(); cachingService.Put("abc", "response", TimeSpan.FromSeconds(0)); string response = cachingService.Get("abc") as string; Assert.Null(response); }
public void Put_NullResponseNotCached() { CachingService cachingService = new CachingService(); cachingService.Put("abc", null, TimeSpan.FromSeconds(10)); string response = cachingService.Get("abc") as string; Assert.Null(response); }
public void AddComplexObjectThenGetReturnsCachedObject() { var sut = new CachingService(); sut.Add(TestKey, new ComplexTestObject()); var actual = sut.Get<ComplexTestObject>(TestKey); var expected = new ComplexTestObject(); Assert.AreEqual(ComplexTestObject.SomeMessage, ComplexTestObject.SomeMessage); Assert.AreEqual(expected.SomeItems, actual.SomeItems); }
public void Put_ResponseCached() { CachingService cachingService = new CachingService(); cachingService.Put("abc", "response", TimeSpan.FromSeconds(10)); string response = cachingService.Get("abc") as string; Assert.Equal("response", response); }
public void DeleteFromCache(string contextUsername) { IAppCache appCache = new CachingService(); KerberosReceiverSecurityToken token = appCache.Get <KerberosReceiverSecurityToken>(contextUsername.ToLower()); if (token != null) { appCache.Remove(contextUsername.ToLower()); } }
public void GetOrAddAndThenGetValueObjectReturnsCorrectType() { var sut = new CachingService(); Func <int> fetch = () => 123; sut.GetOrAdd(TestKey, fetch); var actual = sut.Get <int>(TestKey); Assert.AreEqual(123, actual); }
public void GetOrAddAndThenGetWrongtypeObjectReturnsNull() { var sut = new CachingService(); Func <ComplexTestObject> fetch = () => new ComplexTestObject(); sut.GetOrAdd(TestKey, fetch); var actual = sut.Get <Exception>(TestKey); Assert.IsNull(actual); }
public void GetOrAddAndThenGetWrongtypeObjectReturnsNull() { var sut = new CachingService(); Func<ComplexTestObject> fetch = () => new ComplexTestObject(); sut.GetOrAdd(TestKey, fetch); var actual = sut.Get<Exception>(TestKey); Assert.IsNull(actual); }
public void RemovedItemCannotBeRetrievedFromCache() { var sut = new CachingService(); sut.Add(TestKey, new object()); Assert.NotNull(sut.Get<object>(TestKey)); sut.Remove(TestKey); Assert.Null(sut.Get<object>(TestKey)); }
public void AddWithOffsetThatExpiresReturnsNull() { var sut = new CachingService(); sut.Add(TestKey, "testObject", DateTimeOffset.Now.AddSeconds(1)); Thread.Sleep(1500); Assert.IsNull(sut.Get<string>(TestKey)); }
public void AddWithSlidingReturnsCachedItem() { var sut = new CachingService(); sut.Add(TestKey, "testObject", new TimeSpan(5000)); Assert.AreEqual("testObject", sut.Get<string>(TestKey)); }
public void GetCachedNullableStructTypeParamReturnsType() { var sut = new CachingService(); DateTime? cached = new DateTime(); sut.Add(TestKey, cached); Assert.AreEqual(cached.Value, sut.Get<DateTime>(TestKey)); }
public void GetNullKeyThrowsException() { var sut = new CachingService(); Action act = () => sut.Get<object>(null); act.ShouldThrow<ArgumentNullException>(); }
public void GetWithClassTypeParamReturnsType() { var sut = new CachingService(); var cached = new EventArgs(); sut.Add(TestKey, cached); Assert.AreEqual(cached, sut.Get<EventArgs>(TestKey)); }
public void GetWithIntRetunsDefualtIfNotCached() { var sut = new CachingService(); Assert.AreEqual(default(int), sut.Get<int>(TestKey)); }
public void GetWithNullableIntRetunsCachedNonNullableInt() { var sut = new CachingService(); const int expected = 123; sut.Add(TestKey, expected); Assert.AreEqual(expected, sut.Get<int?>(TestKey)); }
public void GetWithStructTypeParamReturnsType() { var sut = new CachingService(); var cached = new DateTime(2000, 1, 1); sut.Add(TestKey, cached); Assert.AreEqual(cached, sut.Get<DateTime>(TestKey)); }
public void GetWithValueTypeParamReturnsType() { var sut = new CachingService(); const int cached = 3; sut.Add(TestKey, cached); Assert.AreEqual(3, sut.Get<int>(TestKey)); }
public void GetWithWrongClassTypeParamReturnsNull() { var sut = new CachingService(); var cached = new EventArgs(); sut.Add(TestKey, cached); Assert.IsNull(sut.Get<ArgumentNullException>(TestKey)); }
public void GetWithWrongStructTypeParamReturnsNull() { var sut = new CachingService(); var cached = new DateTime(); sut.Add(TestKey, cached); Assert.AreEqual(new TimeSpan(), sut.Get<TimeSpan>(TestKey)); }
public void GetOrAddAndThenGetValueObjectReturnsCorrectType() { var sut = new CachingService(); Func<int> fetch = () => 123; sut.GetOrAdd(TestKey, fetch); var actual = sut.Get<int>(TestKey); Assert.AreEqual(123, actual); }
public void GetOrAddAndThenGetObjectReturnsCorrectType() { var sut = new CachingService(); Func<ComplexTestObject> fetch = () => new ComplexTestObject(); sut.GetOrAdd(TestKey, fetch); var actual = sut.Get<ComplexTestObject>(TestKey); Assert.IsNotNull(actual); }
public void GetOrAddWithPolicyWithCallbackOnRemovedReturnsTheOriginalCachedObject() { var sut = new CachingService(); Func<int> fetch = () => 123; CacheEntryRemovedArguments removedCallbackArgs = null; CacheEntryRemovedCallback callback = (args) => removedCallbackArgs = args; sut.GetOrAdd(TestKey, fetch, new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddMilliseconds(100), RemovedCallback = callback}); var actual = sut.Get<int>(TestKey); sut.Remove(TestKey); //force removed callback to fire while(removedCallbackArgs == null) Thread.Sleep(500); Assert.AreEqual(123, removedCallbackArgs.CacheItem.Value); }
public void GetEmptyKeyThrowsException() { var sut = new CachingService(); Action act = () => sut.Get<object>(""); act.ShouldThrow<ArgumentOutOfRangeException>(); }
public void GetOrAddWithPolicyAndThenGetValueObjectReturnsCorrectType() { var sut = new CachingService(); Func<int> fetch = () => 123; sut.GetOrAdd(TestKey, fetch, new CacheItemPolicy {AbsoluteExpiration = DateTimeOffset.Now.AddHours(1), Priority = CacheItemPriority.NotRemovable}); var actual = sut.Get<int>(TestKey); Assert.AreEqual(123, actual); }
public void AddWithSlidingThatExpiresReturnsNull() { var sut = new CachingService(); sut.Add(TestKey, "testObject", new TimeSpan(750)); Thread.Sleep(1500); Assert.IsNull(sut.Get<string>(TestKey)); }
public void GetOrAddWithPolicyAndThenGetObjectReturnsCorrectType() { var sut = new CachingService(); Func<ComplexTestObject> fetch = () => new ComplexTestObject(); sut.GetOrAdd(TestKey, fetch, new CacheItemPolicy {AbsoluteExpiration = DateTimeOffset.Now.AddHours(1), Priority = CacheItemPriority.NotRemovable}); var actual = sut.Get<ComplexTestObject>(TestKey); Assert.IsNotNull(actual); }
public void AddWithPolicyReturnsCachedItem() { var sut = new CachingService(); sut.Add(TestKey, "testObject", new CacheItemPolicy()); Assert.AreEqual("testObject", sut.Get<string>(TestKey)); }
public void GetOrAddWithOffsetWillAddAndReturnCached() { var sut = new CachingService(); var expectedFirst = sut.GetOrAdd( TestKey, () => new DateTime(2001, 01, 01), DateTimeOffset.Now.AddSeconds(5) ); var expectedSecond = sut.Get<DateTime>(TestKey); Assert.AreEqual(2001, expectedFirst.Year); Assert.AreEqual(2001, expectedSecond.Year); }
public void AddThenGetReturnsCachedObject() { var sut = new CachingService(); sut.Add(TestKey, "testObject"); Assert.AreEqual("testObject", sut.Get<string>(TestKey)); }
public void AddWithOffsetReturnsCachedItem() { var sut = new CachingService(); sut.Add(TestKey, "testObject", DateTimeOffset.Now.AddSeconds(1)); Assert.AreEqual("testObject", sut.Get<string>(TestKey)); }