aliostad / CacheCow

An implementation of HTTP Caching in .NET Core and 4.5.2+ for both the client and the server
MIT License
849 stars 171 forks source link

Add ability to explicitly include/exclude specific actions from CacheCow support #177

Closed Crozin closed 6 years ago

Crozin commented 7 years ago

Hello. Are there any plans to add support for attribute/pattern-based option to explicitly include/exclude specific WebAPI actions in CacheCow Handler? It alread has _ignoreRequestRules but there is no way to extend/replace that filed.

Why do I ask for such an option? Sometimes only 1 or 2 actions could benefit HTTP Cache and there is no need to flood Redis or other storage with useless entries.

aliostad commented 7 years ago

Thank you for your comment. Surely this can be opened up. I will do that and make a release quickly just to expose it.

aliostad commented 7 years ago

Fixed and version 1.3 released to Nuget

Crozin commented 7 years ago

Hey, I see Client-side of CacheCow has been upgraded, however what I was asking about was Server-side part. :-)

Crozin commented 7 years ago

Any chace to reopen that Issue as it targets CacheCow.Server not CacheCow.Client? :)

aliostad commented 7 years ago

Sorry sure. Let me look at it.

joth commented 7 years ago

Hi @aliostad,

Does it make sense to add the same functionality to the server-side cachinghandler?

For example:

diff --git a/src/CacheCow.Server/CachingHandler.cs b/src/CacheCow.Server/CachingHandler.cs
index 7f8987e..b574a67 100644
--- a/src/CacheCow.Server/CachingHandler.cs
+++ b/src/CacheCow.Server/CachingHandler.cs
@@ -155,6 +155,11 @@ EntityTagHeaderValue> ETagValueGenerator
         public static Action<Exception> IgnoreExceptionPolicy { get; private set; }

         /// <summary>
+        /// Rules by which requests get ignored for caching
+        /// </summary>
+        public Func<HttpRequestMessage, bool> IgnoreRequestRules { get; set; }
+
+        /// <summary>
         /// Provides route pattern and linked route pattern
         /// </summary>
        public IRoutePatternProvider RoutePatternProvider
@@ -237,6 +242,11 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques

             try
             {
+                if (IgnoreRequestRules != null && IgnoreRequestRules(request))
+                {
+                    return base.SendAsync(request, cancellationToken);
+                }
+
                 // do the expiry
                 CheckExpiry(request);
aliostad commented 6 years ago

OK, CacheCow is moving away from all that IRoutePatternProvider, and EntityTagStore. 2.0.0 is being released in a few days.