This project is archived and is in readonly mode.
expire_fragment_by_glob() for file-based fragment caching
Reported by Karel Minařík | August 14th, 2008 @ 06:39 PM | in 2.x
This patch adds expire_fragment_by_glob()
method to ActionController::Caching::Fragments
for easy cleaning-up the file-based cache.
I tried to use the Regexp option, but it was too greedy to be usable, and the Hash-based option didn't take into account different hostnames, where single Rails application could be running (eg. application.com and application.es hosting the same app).
It takes the "glob" string as argument, same as the Ruby's Dir[]
or Dir#glob()
.
I added another method, because there is complex switching logic in expire_fragment
(Hash? Regexp?) already. Maybe someone more knowledgeable could refactor it with something like key.is_a?(String) && key.include?('*')
in the expire_fragment()
method...
I am quite sure the implementation could be done better :), but I don't know my way around Rails so well....
Example:
expire_fragment_by_glob('events/{theatre,movie}')
expire_fragment_by_glob('program/**/*')
Motivation was to easily expire fragments for different hostnames where application runs. Moreover, it could be more effective than Regexp-based cleaning for file-based cache.
It is extracted from my current project, where I have it as a class method for main CacheSweeper
class.
Tests are included.
Cheers,
Karel
Comments and changes to this ticket
-
Pratik August 21st, 2008 @ 12:32 PM
- State changed from new to invalid
expire_fragment() already takes a regexp.
-
Karel Minařík August 26th, 2008 @ 09:45 PM
Thanks for comment, Pratik.
expire_fragment() already takes a regexp.
True, but that doesn't take into account different hostnames an application runs on (www.application.org, www.application.com, etc).
Moreover, glob based expiring could be more effective then regexp? (See http://gurge.com/blog/2007/02/04...
Karel
-
Pratik August 26th, 2008 @ 10:02 PM
- Assigned user set to Pratik
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>