public void StaticUsage(bool compressValues, bool useBasic) { TimeSpan cacheLifeTime = TimeSpan.FromSeconds(1); RedisCachingService service = RedisHelpers.GetCustomRedis(compressValues: compressValues, useBasic: useBasic, defaultExpireTimeSpanSeconds: (int)cacheLifeTime.TotalSeconds); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; DateTime startedCaching = DateTime.UtcNow; service.Cache(cachableKey, cachable); DateTime endedCaching = DateTime.UtcNow; ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey); RedisCachingService service2 = RedisHelpers.GetCustomRedis(compressValues: compressValues, useBasic: useBasic, defaultExpireTimeSpanSeconds: (int)cacheLifeTime.TotalSeconds); ICachedObject <Foobar> existsRetrievedWrapper2 = service2.Retrieve <Foobar>(cachableKey); Assert.True(RedisHelpers.CheckFooBarEquality(cachable, existsRetrievedWrapper.Value)); Assert.True(RedisHelpers.CheckFooBarEquality(existsRetrievedWrapper.Value, existsRetrievedWrapper2.Value)); // they aren't reference equal Assert.NotEqual(existsRetrievedWrapper.Value, existsRetrievedWrapper2.Value); service2.Clear(); Assert.Null(service.Retrieve <Foobar>(cachableKey)); }
public void DoubleRetrieve(bool compressValues, bool useBasic) { RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; service.Cache(cachableKey, cachable); ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey); ICachedObject <Foobar> retrievedWrapper = service.Retrieve <Foobar>(cachableKey); Assert.NotNull(existsRetrievedWrapper); Assert.NotNull(retrievedWrapper); Assert.True(RedisHelpers.CheckFooBarEquality(cachable, existsRetrievedWrapper.Value)); Assert.True(RedisHelpers.CheckFooBarEquality(existsRetrievedWrapper.Value, retrievedWrapper.Value)); Assert.Single(service); }
public void Remove(bool compressValues, bool useBasic) { RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; DateTime startedCaching = DateTime.UtcNow; service.Cache(cachableKey, cachable); DateTime endedCaching = DateTime.UtcNow; ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey); service.Remove(cachableKey); ICachedObject <Foobar> retrievedWrapper = service.Retrieve <Foobar>(cachableKey); Assert.Empty(service); Assert.NotNull(existsRetrievedWrapper); Assert.Null(retrievedWrapper); }
public void AutomatedCustomExpiration(bool compressValues, bool useBasic) { RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; DateTime startedCaching = DateTime.UtcNow; // just setting it long enough that even slow machines can pass it service.Cache(cachableKey, cachable, DateTime.UtcNow, DateTime.UtcNow.AddMilliseconds(550));; DateTime endedCaching = DateTime.UtcNow; ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey); Thread.Sleep(560); ICachedObject <Foobar> retrievedWrapper = service.Retrieve <Foobar>(cachableKey); Assert.NotNull(existsRetrievedWrapper); Assert.Null(retrievedWrapper); }
public void AutomatedExpiration(bool compressValues, bool useBasic) { TimeSpan cacheLifeTime = TimeSpan.FromSeconds(1); RedisCachingService service = RedisHelpers.GetCustomRedis(compressValues: compressValues, useBasic: useBasic, defaultExpireTimeSpanSeconds: (int)cacheLifeTime.TotalSeconds); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; DateTime startedCaching = DateTime.UtcNow; service.Cache(cachableKey, cachable); DateTime endedCaching = DateTime.UtcNow; ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey); Thread.Sleep(1000); ICachedObject <Foobar> retrievedWrapper = service.Retrieve <Foobar>(cachableKey); Assert.NotNull(existsRetrievedWrapper); Assert.Null(retrievedWrapper); }
public void ManualExpiration(bool compressValues, bool useBasic) { TimeSpan cacheLifeTime = TimeSpan.FromMinutes(5); RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; DateTime startedCaching = DateTime.UtcNow; service.Cache(cachableKey, cachable); DateTime endedCaching = DateTime.UtcNow; ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey); service.Invalidate(cachableKey); ICachedObject <Foobar> retrievedWrapper = service.Retrieve <Foobar>(cachableKey); Assert.Empty(service); Assert.NotNull(existsRetrievedWrapper); Assert.Null(retrievedWrapper); }
public void AddKvp(bool compressValues, bool useBasic) { TimeSpan cacheLifeTime = TimeSpan.FromMinutes(5); RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; KeyValuePair <string, ICachedObjectBasic> item = RedisHelpers.GetCachableKvp(DateTime.UtcNow, cacheLifeTime, cachable, cachableKey); service.Add(item); ICachedObject <Foobar> result = service.Retrieve <Foobar>(cachableKey); Assert.True(RedisHelpers.CheckFooBarEquality(cachable, result.Value)); }
public void Clear(bool compressValues, bool useBasic) { RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic); service.Clear(); string cachableKey = RedisHelpers.CachableKey; Foobar cachable = RedisHelpers.GetCachableObject(); service.Cache <Foobar>(cachableKey, cachable); Assert.Single(service); ICachedObject <Foobar> cached = service.Retrieve <Foobar>(cachableKey); Assert.True(RedisHelpers.CheckFooBarEquality(cachable, cached.Value)); service.Clear(); Assert.Empty(service); }
public void Retrieval(bool compressValues, bool useBasic) { TimeSpan cacheLifeTime = TimeSpan.FromMinutes(5); RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; DateTime startedCaching = DateTime.UtcNow; Thread.Sleep(10); service.Cache(cachableKey, cachable); Thread.Sleep(10); DateTime endedCaching = DateTime.UtcNow; ICachedObject <Foobar> retrievedWrapper = service.Retrieve <Foobar>(cachableKey); Assert.NotNull(retrievedWrapper); Assert.True(RedisHelpers.CheckFooBarEquality(cachable, retrievedWrapper.Value)); Assert.True(retrievedWrapper.CachedTime >= startedCaching && retrievedWrapper.CachedTime <= endedCaching); Assert.True(retrievedWrapper.ExpireTime >= startedCaching.Add(cacheLifeTime) && retrievedWrapper.ExpireTime <= endedCaching.Add(cacheLifeTime)); }
public void CopyTo(bool compressValues, bool useBasic) { RedisCachingService service = RedisHelpers.GetRedis(compressValues: compressValues, useBasic: useBasic); service.Clear(); Foobar cachable = RedisHelpers.GetCachableObject(); string cachableKey = RedisHelpers.CachableKey; service.Cache(cachableKey, cachable); ICachedObject <Foobar> existsRetrievedWrapper = service.Retrieve <Foobar>(cachableKey); KeyValuePair <string, ICachedObjectBasic>[] cache = new KeyValuePair <string, ICachedObjectBasic> [1]; service.CopyTo(cache, 0); Assert.NotNull(cache); Assert.NotEmpty(cache); Assert.Single(cache); Foobar returned = RedisHelpers.SerializationService.DeserializeObject <Foobar>((string)cache[0].Value.UntypedValue, RedisHelpers.SerializationSettings); Assert.NotNull(returned); Assert.NotEqual(cachable, returned); Assert.True(RedisHelpers.CheckFooBarEquality(existsRetrievedWrapper.Value, returned)); Assert.Equal(cachableKey, ((RedisId)cache[0].Key).ObjectIdentifier); }