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