This project is archived and is in readonly mode.

#832 ✓invalid
Karel Minařík

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

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>

Attachments

Pages