Skip to content

Commit a4a5844

Browse files
Allowed all cache to dipose
1 parent f3a28f2 commit a4a5844

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

src/DotNetToolkit.Repository.Caching.InMemory/InMemoryCache.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,17 @@ public int Increment([NotNull] string key, int defaultValue, int incrementValue)
120120
}
121121

122122
#endregion
123+
124+
#region Implementation of ICache
125+
126+
/// <summary>
127+
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
128+
/// </summary>
129+
public void Dispose()
130+
{
131+
_cache.Dispose();
132+
}
133+
134+
#endregion
123135
}
124136
}

src/DotNetToolkit.Repository.Caching.Redis/RedisCache.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,23 @@ public int Increment([NotNull] string key, int defaultValue, int incrementValue)
251251
}
252252

253253
#endregion
254+
255+
#region Implementation of ICache
256+
257+
/// <summary>
258+
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
259+
/// </summary>
260+
public void Dispose()
261+
{
262+
if (_lazyConnection.IsValueCreated)
263+
{
264+
var conn = _lazyConnection.Value;
265+
266+
conn.Close(false);
267+
conn.Dispose();
268+
}
269+
}
270+
271+
#endregion
254272
}
255273
}

src/DotNetToolkit.Repository/Configuration/Caching/ICache.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/// <summary>
66
/// Represents an interface for caching query data within the repositories.
77
/// </summary>
8-
public interface ICache
8+
/// <seealso cref="IDisposable" />
9+
public interface ICache : IDisposable
910
{
1011
/// <summary>
1112
/// Create or overwrite an entry in the cache.

src/DotNetToolkit.Repository/Configuration/Caching/Internal/NullCache.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ public int Increment(string key, int defaultValue, int incrementValue)
2626
{
2727
return 1;
2828
}
29+
30+
public void Dispose() { }
2931
}
3032
}

0 commit comments

Comments
 (0)