diff --git a/DevTrends.MvcDonutCaching/OutputCacheManager.cs b/DevTrends.MvcDonutCaching/OutputCacheManager.cs
index 6cd0387..b804cd5 100644
--- a/DevTrends.MvcDonutCaching/OutputCacheManager.cs
+++ b/DevTrends.MvcDonutCaching/OutputCacheManager.cs
@@ -136,9 +136,54 @@ public void RemoveItems([AspMvcController] string controllerName, [AspMvcAction]
/// The name of the controller action method.
/// A dictionary that contains the parameters for a route.
public void RemoveItems([AspMvcController] string controllerName, [AspMvcAction] string actionName, RouteValueDictionary routeValues)
+ {
+ RemoveItems(controllerName, actionName, routeValues, (keysToDelete, routeValue) =>
+ {
+ var keyFrag = _keyBuilder.BuildKeyFragment(routeValue);
+ if (string.IsNullOrEmpty(keyFrag))
+ {
+ return keysToDelete;
+ }
+
+ return keysToDelete.Where(_ => !string.IsNullOrEmpty(_) && _.Contains(keyFrag));
+ });
+ }
+
+ ///
+ /// Removes all output cache entries for the specified controller, action and parameters.
+ ///
+ /// The name of the controller that contains the action method.
+ /// The name of the controller action method.
+ /// A dictionary that contains the parameters for a route.
+ ///
+ /// A custom filter function that allows selective removal of cache entries based on route parameters.
+ ///
+ /// This function receives:
+ ///
+ ///
+ /// - A collection of cache entry keys (`IEnumerable<string>`)
+ ///
+ ///
+ /// - A route key-value pair (`KeyValuePair<string, object>`)
+ ///
+ ///
+ /// It returns a filtered subset of keys to be removed.
+ ///
+ ///
+ ///
+ /// keysToDelete.Where((string _) =>
+ /// !string.IsNullOrEmpty(_) &&
+ /// _.Contains(routeValue.Key) &&
+ /// _.Contains(routeValue.Value.ToString()))
+ ///
+ ///
+ ///
+ /// This example filters only those cache keys that are not null/empty and contain both the route key and value. It's useful when the action has multiple parameters and you don't want to match all of them.
+ ///
+ ///
+ public void RemoveItems([AspMvcController] string controllerName, [AspMvcAction] string actionName, RouteValueDictionary routeValues, Func, KeyValuePair, IEnumerable> parameterFilter)
{
var enumerableCache = _outputCacheProvider as IEnumerable>;
-
if (enumerableCache == null)
{
throw new NotSupportedException("Ensure that your custom OutputCacheProvider implements IEnumerable>.");
@@ -170,14 +215,7 @@ public void RemoveItems([AspMvcController] string controllerName, [AspMvcAction]
}
}
- var keyFrag = _keyBuilder.BuildKeyFragment(routeValue);
-
- if (string.IsNullOrEmpty(keyFrag))
- {
- continue;
- }
-
- keysToDelete = keysToDelete.Where(_ => !string.IsNullOrEmpty(_) && _.Contains(keyFrag));
+ keysToDelete = parameterFilter(keysToDelete, routeValue);
}
}