Skip to content

Commit

Permalink
Clear Cache
Browse files Browse the repository at this point in the history
Added Clear Cache option to Cache Manager to remove all cached items
irrespective of tags.
  • Loading branch information
PatelVish committed Jan 30, 2015
1 parent ef14ba4 commit 29d5807
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Source/EntityFramework.Extended/Caching/CacheManager.cs
Expand Up @@ -415,6 +415,15 @@ public virtual void Set(CacheKey cacheKey, object value, CachePolicy cachePolicy
provider.Set(cacheKey, value, cachePolicy);
}

/// <summary>
/// Clears all entries from the cache
/// </summary>
public virtual void Clear()
{
var provider = ResolveProvider();
provider.ClearCache();
}


/// <summary>
/// Gets the registered <see cref="ICacheProvider"/> from <see cref="Locator"/>.
Expand Down
6 changes: 6 additions & 0 deletions Source/EntityFramework.Extended/Caching/ICacheProvider.cs
Expand Up @@ -75,5 +75,11 @@ public interface ICacheProvider
/// <param name="value">The object to insert.</param>
/// <param name="cachePolicy">A <see cref="CachePolicy"/> that contains eviction details for the cache entry.</param>
bool Set(CacheKey cacheKey, object value, CachePolicy cachePolicy);

/// <summary>
/// Clears all entries from the cache
/// </summary>
/// <returns>The number of items removed.</returns>
long ClearCache();
}
}
10 changes: 10 additions & 0 deletions Source/EntityFramework.Extended/Caching/MemoryCacheProvider.cs
Expand Up @@ -157,6 +157,16 @@ public bool Set(CacheKey cacheKey, object value, CachePolicy cachePolicy)
return true;
}

/// <summary>
/// Clears all entries from the cache
/// </summary>
/// <returns></returns>
public long ClearCache()
{
return MemoryCache.Default.Trim(100);
}


// internal for testing
internal static string GetKey(CacheKey cacheKey)
{
Expand Down

0 comments on commit 29d5807

Please sign in to comment.