public void ObjectRetrievedFromFirstLevelCacheShouldNotBeClonedIfTheyAreFromASpecificNameSpace() { var namespaceCloningProvider = new NamespacesBasedCloningProvider(new [] { "System" }); var cache = new SquirrelCache(_config, namespaceCloningProvider, _serializationProvider); var testObject2 = EqualityComparer <string> .Default; var serializedTestObject2 = KrakenSerializer.Serialize(testObject2); var key1 = RandomKey(); var key2 = RandomKey(); cache.Set(key1, _serializedTestObject); cache.Set(key2, serializedTestObject2); var obj1_1 = cache.Get <object>(key1).Value; var obj1_2 = cache.Get <object>(key1).Value; Assert.NotNull(obj1_1); Assert.True(ReferenceEquals(obj1_1, obj1_2)); var obj2_1 = cache.Get <object>(key2).Value; var obj2_2 = cache.Get <object>(key2).Value; Assert.NotNull(obj2_1); Assert.False(ReferenceEquals(obj2_1, obj2_2)); }
public void ObjectRetrievedFromFirstLevelCacheShouldAlwaysBeCloned() { var cache = new SquirrelCache(_config, _alwaysCloningProvider, _serializationProvider); var key = RandomKey(); cache.Set(key, _serializedTestObject); var obj1 = cache.Get <object>(key).Value; var obj2 = cache.Get <object>(key).Value; Assert.NotNull(obj1); Assert.False(ReferenceEquals(obj1, obj2)); }
public void UsingACustomSerializationProviderShouldWork() { var key = Guid.NewGuid().ToString(); var sp = new BinaryFormatterSerializationProvider(); var objBytes = sp.Serialize(_testObject); var cacheRepository = new SquirrelCache(_config, _noCloningProvider, sp); cacheRepository.Set(key, objBytes); Assert.Equal(_testObject.Value, cacheRepository.Get <CachingTestClass>(key).Value.Value); }
public void AddingItemToCacheWithoutTtlShouldStoreIt() { var key = Guid.NewGuid().ToString(); _cacheRepository.Set(key, _serializedTestObject); Assert.Equal(_testObject.Value, _cacheRepository.Get <CachingTestClass>(key).Value.Value); }