This project is archived and is in readonly mode.
cache "Convenience accessor" in controllers create fragments that expire_fragment can't expire
Reported by sudara | August 10th, 2010 @ 12:36 AM
Typical Disclaimer: Maybe I'm missing something, but this is not working/intuitive and causing problems. At best it's a doc issue?
The cache 'helper in controllers looks like so
# actionpack/lib/action_controller/caching.rb, line 76
def cache(key, options = {}, &block)
if cache_configured?
cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
else
yield
end
end
Note that expand_cache_key is passed :controller, which namespaces the cache key.
If I want to explicitly expire this fragment, using (naturally) expire_fragment, it is impossible. This is because expire_fragment calls fragment_cache_key which explicitly sets the namespace to :views
def fragment_cache_key(key)
ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views)
end
This leaves the developer having to create their own version of "expires_fragment" for controller namedspaced fragments. Or, in my case, I just overrode the controllers "cache" accessor so that it didn't namespace it with :controller, because frankly, it doesn't matter to me where the item is cached from.
I'm not familiar enough with how rails is organized to make a best practice call for how this can be resolved without ruffling feathers, but it seemed worth bringing up, as it's a head-scratching moment! Personally, the namespacing is something i don't like as a developer, but I imagine a patch that removes it would not be accepted.
Comments and changes to this ticket
-
Santiago Pastorino February 2nd, 2011 @ 05:00 PM
- 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.
-
Santiago Pastorino February 2nd, 2011 @ 05:00 PM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>