Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

expire_fragment_by_glob() for file-based fragment caching

#832

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

Reported by Karel Minařík · August 14th, 2008 @ 06:39 PM

State: invalid
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Pratik
    Pratik
    • State changed from new to invalid

    expire_fragment() already takes a regexp.

    August 21st, 2008 @ 12:32 PM

  2. Karel Minařík
    Karel Minařík

    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

    August 26th, 2008 @ 09:45 PM

  3. Pratik
    Pratik
    • Assigned user set to Pratik

    August 26th, 2008 @ 10:02 PM

  4. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:23 AM