Skip to content

Commit

Permalink
feat: dispose MemoryCache
Browse files Browse the repository at this point in the history
  • Loading branch information
alastairtree committed Mar 4, 2018
1 parent 1d71fc0 commit 64a5bac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LazyCache/ICacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace LazyCache
{
public interface ICacheProvider
public interface ICacheProvider : IDisposable
{
void Set(string key, object item, MemoryCacheEntryOptions policy);
object Get(string key);
Expand Down
4 changes: 4 additions & 0 deletions LazyCache/Mocks/MockCachingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,9 @@ public Task<T> GetOrCreateAsync<T>(string key, Func<ICacheEntry, Task<T>> func)
{
return func(null);
}

public void Dispose()
{
}
}
}
7 changes: 6 additions & 1 deletion LazyCache/Providers/MemoryCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LazyCache.Providers
{
public class MemoryCacheProvider : ICacheProvider
{
private readonly IMemoryCache cache;
internal readonly IMemoryCache cache;

public MemoryCacheProvider() : this(new MemoryCache(new MemoryCacheOptions()))
{
Expand Down Expand Up @@ -41,5 +41,10 @@ public Task<T> GetOrCreateAsync<T>(string key, Func<ICacheEntry, Task<T>> factor
{
return cache.GetOrCreateAsync(key, factory);
}

public void Dispose()
{
cache?.Dispose();
}
}
}

0 comments on commit 64a5bac

Please sign in to comment.