tag:blogger.com,1999:blog-2889416825250254881.post4764699420503183220..comments2024-01-27T11:41:32.146+00:00Comments on Byte Rot: CacheCow 0.4 released: new features and a breaking changealiostadhttp://www.blogger.com/profile/05695786967974402749noreply@blogger.comBlogger21125tag:blogger.com,1999:blog-2889416825250254881.post-49187596517153399862016-08-25T22:40:57.876+01:002016-08-25T22:40:57.876+01:00I had this problem too because I had a BaseControl...I had this problem too because I had a BaseController with public bool and public int? function. I changed these to protected instead of public which worked.breazeweazehttps://www.blogger.com/profile/10950173508733363422noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-35878623254949734032016-05-20T17:55:56.466+01:002016-05-20T17:55:56.466+01:00I can do that?
Anyway, solved it with a delegating...I can do that?<br />Anyway, solved it with a delegating handler on top of the cachecow one:<br /><br /><br />public class HandleFirstTimeEtagResultDelegatingHandler : DelegatingHandler<br />{<br /> protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)<br /> {<br /> HttpResponseMessage response = await base.SendAsync(request, cancellationToken);<br /> HttpStatusCode statusCodeSuggestion = response.StatusCode;<br /> if (statusCodeSuggestion == HttpStatusCode.OK)<br /> {<br /> HttpHeaderValueCollection etagValuesFromRequest = request.Headers.IfNoneMatch;<br /> EntityTagHeaderValue responseEtagSuggestion = response.Headers.ETag;<br /> if (etagValuesFromRequest != null && responseEtagSuggestion!=null && etagValuesFromRequest.Any(i => responseEtagSuggestion.Equals(i)))<br /> {<br /> response.StatusCode = HttpStatusCode.NotModified;<br /> response.ReasonPhrase = new HttpStatusCodeResult(HttpStatusCode.NotModified).StatusDescription;<br /> response.Content.Dispose();<br /> response.Content = null;<br /> }<br /> }<br /> return response;<br /> }<br />}<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-9381684883779833512016-05-20T16:26:47.594+01:002016-05-20T16:26:47.594+01:00Why don't you use static file handlers that ha...Why don't you use static file handlers that have a built in support for output caching? aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-17986315469778097592016-05-20T15:33:01.536+01:002016-05-20T15:33:01.536+01:00So, how does it work now?
I'm facing the same ...So, how does it work now?<br />I'm facing the same problem.<br />We have lots of images as static content that get updated via web deploy. So, the application gets restarted.<br />Then we don't want the clients to have to re-fetch images if they haven't actually changed.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-79249486006483115512014-07-29T21:48:19.910+01:002014-07-29T21:48:19.910+01:00Can you please send me your routing and controller...Can you please send me your routing and controllers?aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-75465979748615189802014-07-28T19:02:43.126+01:002014-07-28T19:02:43.126+01:00Hi. Based on the information in this article I ad...Hi. Based on the information in this article I added the following to my CachingHander created in my Application_Start (Global.asax.cs).<br /><br /> var cachecow = new CachingHandler(GlobalConfiguration.Configuration);<br /><br />cachecow.CacheControlHeaderProvider = new AttributeBasedCacheControlPolicy(<br /> new CacheControlHeaderValue()<br /> {<br /> NoCache = true<br /> }).GetCacheControl;<br /><br />I now get the following error ,"exceptionMessage":"Multiple actions were found that match the request:...<br /><br />Any advice in troubleshooting/resolving would be appreciated. Thanks<br />Mulk87https://www.blogger.com/profile/09286690810333296667noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-58797164906307014582014-07-20T13:33:10.433+01:002014-07-20T13:33:10.433+01:00Yes, that becomes a necessity. However, this becom...Yes, that becomes a necessity. However, this becomes brittle since deeper layers now need to understand about more superficial layers (API Layer) and know their resources.<br /><br />One of the solutions is to generate the cache key from the resource which requires a call to the backend. I have a plan to support this scenario.aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-64600938549083806312014-07-19T21:32:28.990+01:002014-07-19T21:32:28.990+01:00Hi. Going back to the point you make in the post ...Hi. Going back to the point you make in the post about legacy systems changing state and this not being picked up by the Handler, is it then OK (Best Practice) to manually remove the data from the store? (SQL, Memcache, whatever) ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-35806271908861238852014-06-04T20:34:59.084+01:002014-06-04T20:34:59.084+01:00Is this causing a problem? It is a known issue but...Is this causing a problem? It is a known issue but if it is too much of a problem, raise an issue in Github and I will have a look to fix it.aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-1394899696773187442014-06-04T19:30:00.394+01:002014-06-04T19:30:00.394+01:00I am trying to by-pass caching on the server for s...I am trying to by-pass caching on the server for some routes in my Web-Api project however when using an attribute based caching policy, I noticed based on the HTTP responses that the policy works but the SQL Server store is still updated with the cache state info. How can I prevent the CacheState table from adding and updating for resources I do not want cached. I attempted to use the HTTPCacheControlPolicy with the cacheControlHeaderValueFactory parameter but it is not entirely clear to me how this should be implemented. Can you please shed some light as to how I can go about addressing this issue. thanks.Jay Deanhttps://www.blogger.com/profile/02243623846361685106noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-73463411604383744032013-04-05T20:33:25.992+01:002013-04-05T20:33:25.992+01:00OK, nice! :)
I was going to create the issue but ...OK, nice! :)<br /><br />I was going to create the issue but I saw that you already created it.Anonymoushttps://www.blogger.com/profile/17509174938453325653noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-54223607102405968322013-04-05T18:39:02.250+01:002013-04-05T18:39:02.250+01:00I see - you are right. Can you please create an is...I see - you are right. Can you please create an issue on the GitHub? I need to make a new release, I will add this as part of it :)aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-33551913461555256512013-04-05T18:35:59.054+01:002013-04-05T18:35:59.054+01:00The only benefit I thought was that I could restar...The only benefit I thought was that I could restart the server without the eTags being invalidated. So, the eTags that the client have stored, associated with the resources, would still be valid.<br /><br />Anyway, that was just an idea and would have the same results as using the GUID as eTag and persisting it to a database.Anonymoushttps://www.blogger.com/profile/17509174938453325653noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-27975122030083073592013-04-05T09:20:51.122+01:002013-04-05T09:20:51.122+01:00So sorry for me asking, what benefit does the gene...So sorry for me asking, what benefit does the generation of eTag based on content provides over GUID if we are not checking with content in subsequent calls?aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-46176364704520827112013-04-05T02:36:49.486+01:002013-04-05T02:36:49.486+01:00As a matter of fact I was thinking on generating t...As a matter of fact I was thinking on generating the eTags based on the content and then store them on the memory. <br /><br />With that in mind, every first time that the server goes to the backend to get the resource, it should store that eTag and on the following requests to the same resource, it should reuse the stored eTag. On the PUT, PATCH, DELETE and POST requests for that resource, the server should invalidate the resource's eTag and regenerate it. Wouldn't it be possible? <br /><br />Anyway, your current implementation already fully satisfy my requirements. Thanks again!Anonymoushttps://www.blogger.com/profile/17509174938453325653noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-86163766161186739422013-04-05T02:11:46.580+01:002013-04-05T02:11:46.580+01:00Yes, it really helped a lot! Thank you!Yes, it really helped a lot! Thank you!Anonymoushttps://www.blogger.com/profile/17509174938453325653noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-13502284254284083182013-04-04T15:40:51.548+01:002013-04-04T15:40:51.548+01:00OK, not to worry, I will implement this later. But...OK, not to worry, I will implement this later. But I would say it is 10 times better to use an InMemory repo and accept drawback of restarts rather than generate eTag based on the content since win the first, server just goes to backend once to get the data and then sets the eTag. If you do based on content, you have to always go to backend to get the data and generate eTag. So you actually would not use most of the benefits of caching. aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-84286839036186440012013-04-04T15:30:33.409+01:002013-04-04T15:30:33.409+01:00Hi aliostad,
Thanks for your fast reply. I will u...Hi aliostad,<br /><br />Thanks for your fast reply. I will use the persistent cache with MongoDB for now.<br /><br />I didn't understand very well the part about putting the header on the REQUEST. Just to clarify, when talking about the server, shouldn't the header be put on the RESPONSE?<br /><br />Thanks again.<br />Anonymoushttps://www.blogger.com/profile/17509174938453325653noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-15944510461884294222013-04-04T15:12:25.197+01:002013-04-04T15:12:25.197+01:00Did the answer help?Did the answer help?aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-9342253907018836012013-04-03T19:56:35.264+01:002013-04-03T19:56:35.264+01:00Hi Guilherme,
Default implementation of eTag stor...Hi Guilherme,<br /><br />Default implementation of eTag store is an InMemory one but you could use persistent ones such as Memcached, SQL Server, Redis, etc. So your best bet is to use a persistent one so it does not be lost. It seems that you have already taken a note of that.<br /><br />I have been thinking of adding a feature to generate eTag based on the content. This is not there yet and might be a while until done.<br /><br />Your best option is to do this:<br /><br />1- Define a custom header name such as x-cachecow-content-hash<br />2- Pass that when as one of the varyByHeaders headers when you initialise the CachingHandler<br />3- Generate the content hash and add the header to REQUEST (and not RESPONSE)<br />4- Create a Func and set to the value of ETagValueGenerator to read from the value of the headers passed.<br /><br />Any problems let me know.<br /><br /><br /><br />aliostadhttps://www.blogger.com/profile/05695786967974402749noreply@blogger.comtag:blogger.com,1999:blog-2889416825250254881.post-13714855294667775492013-04-02T22:14:24.546+01:002013-04-02T22:14:24.546+01:00Hi aliostad. I really appreciated your work. I was...Hi aliostad. I really appreciated your work. I was working on Asp.NET Web API Service, particularly on the cache part, and I found your implementation really helpful.<br /><br />I would be very grateful if you could help me with a question. I saw in the CachingHandler class that the eTag construction is based on a random Guid, but those eTags would be lost if you restart the service (if you don't use a db to store them). I'd like to know if would it be possible to generate the eTag based on the response payload or if there is a reason for that generation to be made the way it is now.<br /><br />I would be very grateful if you could help me with this doubt.<br /><br />Congratulations for you nice work!<br /><br />GuilhermeAnonymoushttps://www.blogger.com/profile/17509174938453325653noreply@blogger.com