moonpyk / mvcdonutcaching

ASP.NET MVC Extensible Donut Caching brings donut caching to ASP.NET MVC 3 and later. The code allows you to cache all of your page apart from one or more Html.Actions which can be executed every request. Perfect for user specific content.
https://github.com/moonpyk/mvcdonutcaching
MIT License
142 stars 50 forks source link

Caching Response Headers #28

Open LinuxDoku opened 10 years ago

LinuxDoku commented 10 years ago

Hello,

is it possible to cache response headers which are set via custom ActionFilter's?

Our application has a ActionFilter which set's the Content-Range header by inspecting the view model. This header get's lost when donut caching is serving the site from cache.

Thank you!

migig commented 9 years ago

@LinuxDoku We have a similar problem. We need to update a cookie, but the action is cached, so the cookie doesn't change. How did you solve your problem?

LinuxDoku commented 9 years ago

We have no fix for this yet. ATM we`re sending a timestamp at the end of the url to disable the caching for this request.

Our trainee has implemented correct header caching in mvcdonutcaching but we had no time to code review this feature. He meant it was quite simple to develop - maybe you could give it a try.

migig commented 9 years ago

@LinuxDoku If / once you're comfortable sharing your code, that would be awesome. I'd try! clean it up and submit it as a PR to @moonpyk.

Been digging into the codebase myself, but don't have a clue where to begin.

LinuxDoku commented 9 years ago

@irii could you commit your fix here on github? Thx, will bring some energy to the office on tuesday ;)

migig commented 9 years ago

@LinuxDoku @irii :smiley: :beer:

ghost commented 9 years ago

@LinuxDoku @migig https://github.com/irii/mvcdonutcaching/commit/a18af56f9da8a0da9bd8689ca684acdb147519be hope it works :smiley:

LinuxDoku commented 9 years ago

@irii nice code!

Simply adding the headers to the attribute (in a semicolon separated list) is enough?

[DonutCache(CachedHeaders = "Content-Range;x-cache-item")]

Can't wait to see this in Zion ;)

migig commented 9 years ago

@LinuxDoku @irii Ohhhh, OK, I think I understand what you did, please correct me if I'm wrong.

Your problem was that you are setting headers, but they are excluded from the cache. So your fix allows you to manually specify which headers to cache.

My problem is certain headers ARE cached, and I want them excluded. Specifically, cookies.

Your code is nice and useful though! :smiley:

mahdi87gh commented 9 years ago

Hi, I need to force server for cache a ajax request different than normal request. I used this line of code and it works, but I need an equivalent code for donut. Is it possible? [OutputCache(CacheProfile = "long", Location = System.Web.UI.OutputCacheLocation.Server, VaryByParam = "*", VaryByHeader = "X-Requested-With")]