From 772ab3c92132196b63b15c92a262acc0bcce228f Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 30 Aug 2013 15:14:44 -0700 Subject: [PATCH] Cahce.Remove is now void Added tests for Cache.Remove --- .../CacheTests/CachedFixture.cs | 17 +++++++++++++++++ NzbDrone.Common/Cache/Cached.cs | 9 +-------- NzbDrone.Common/Cache/ICached.cs | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/NzbDrone.Common.Test/CacheTests/CachedFixture.cs b/NzbDrone.Common.Test/CacheTests/CachedFixture.cs index 4a1cf9021..1d91558a6 100644 --- a/NzbDrone.Common.Test/CacheTests/CachedFixture.cs +++ b/NzbDrone.Common.Test/CacheTests/CachedFixture.cs @@ -48,6 +48,23 @@ namespace NzbDrone.Common.Test.CacheTests _cachedString.Find("Key").Should().Be("New"); } + + [Test] + public void should_be_able_to_remove_key() + { + _cachedString.Set("Key", "Value"); + + _cachedString.Remove("Key"); + + _cachedString.Find("Key").Should().BeNull(); + } + + [Test] + public void should_be_able_to_remove_non_existing_key() + { + _cachedString.Remove("Key"); + } + [Test] public void should_store_null() { diff --git a/NzbDrone.Common/Cache/Cached.cs b/NzbDrone.Common/Cache/Cached.cs index 61d4733e4..7269a9a53 100644 --- a/NzbDrone.Common/Cache/Cached.cs +++ b/NzbDrone.Common/Cache/Cached.cs @@ -61,17 +61,10 @@ namespace NzbDrone.Common.Cache return value.Object; } - public T Remove(string key) + public void Remove(string key) { CacheItem value; _store.TryRemove(key, out value); - - if (value == null) - { - return default(T); - } - - return value.Object; } public T Get(string key, Func function, TimeSpan? lifeTime = null) diff --git a/NzbDrone.Common/Cache/ICached.cs b/NzbDrone.Common/Cache/ICached.cs index 7e68b395b..1c9e50812 100644 --- a/NzbDrone.Common/Cache/ICached.cs +++ b/NzbDrone.Common/Cache/ICached.cs @@ -13,7 +13,7 @@ namespace NzbDrone.Common.Cache void Set(string key, T value, TimeSpan? lifetime = null); T Get(string key, Func function, TimeSpan? lifeTime = null); T Find(string key); - T Remove(string key); + void Remove(string key); ICollection Values { get; } }