This project is archived and is in readonly mode.
Action Caching ignore response content type and request header
-
Chris Hapgood
There are some warts. Some that come to mind: determination of available content_types, cache expiration and backwards compatibility.
content_type availability
To determine the content types available for a cache response, I see two possible solutions:
- query the cache story for the keys at a given prefix (the base key, without a content_type suffix) and extract all the existing suffixes.
- have the user specify the available content types in the macro (caches_action :show, :content_types => [:xml, :pdf]
Option 1 is DRY, but required a separate cache query -and I wasn't sure all cache stores could support a wildcard key lookup. Option 2 was pragmatic and I selected it.
cache expiration
Cache expiration appears to have always been a bit clunky when dealing with multiple content types. It appears that a wildcard approach is almost required here. I chose, for pragmatic reasons, to stick with specific expiration by content type. It's not pretty, but I don't think it was before either.
backwards compatibility
Backwards compatibility is important because I decided to let the user specify the content types (potentially) available from cache. Existing code won't have such a specification. In that case, I assume that the :all generic content type applies for matching. This makes the respond_to code work as expected, but may lead to unhelpful cache key extensions. I could use some help here...
Rails 3
Oh yeah. I did not test my patch against master. Not even sure if it is still appropriate.
-
Andrea Campi
- Tag changed from actionpack responder, action_controller, caches_action, responder to actionpack responder, action_controller, caches_action, patch, responder
The same issue does apply to edge; unfortunately your patch would require quite a few changes, code in master changed quite a bit.
-
Chris Hapgood
Andrea,
Thanks for the update. I will work on getting this code to work with master. It is working wonderfully in 2-3-stable.-Chris
-
Neeraj Singh
- Importance changed from to Low
This is a tough one. I spent some time looking at the issue and here are my findings.
If you sent a request for .xml or .js extension at the end then everything works fine.
However if say HTTP_ACCEPT attribute is "text/xml" then there are a number of issues. Remember action caching puts a before_filter which reads from the cache to find out if a cache already exists or not. However in this case in order to find out if a cache exists for mime type html or for xml rails needs to parse HTTP_ACCEPT. Parsing actually happens only inside the process body and not in a filter.
In the before_filter controller has access to params[:format] and that is why a request with .xml or .js works.
I will discuss this issue with JV and will update here.
-
Neeraj Singh
Added to documentation that action caching does not play well with HTTP_ACCEPT attribute.
https://github.com/lifo/docrails/commit/3ac844deec6070f35634acca0ae...
-
rails
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale
