Method: Merb::Cache::ControllerInstanceMethods#expire_page

Defined in:
lib/merb-cache/cache-page.rb

#expire_page(options) ⇒ Object

Expires the page identified by the key computed after the parameters

Parameter

options<String,Hash>

The options that will be passed to #expire_key_for

Examples (See Merb::Cache#expire_key_for for more options)

# will expire path/to/page/cache/news/show/1.html
expire_page(:key => url(:news,News.find(1)))

# will expire path/to/page/cache/news/show.html
expire_page(:action => 'show', :controller => 'news')

# will expire path/to/page/cache/news/show*
expire_page(:action => 'show', :match => true)

# will expire path/to/page/cache/news/show.js
expire_page(:action => 'show', :extension => 'js')


83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/merb-cache/cache-page.rb', line 83

def expire_page(options)
  config_dir = Merb::Controller._cache.config[:cache_html_directory]
  Merb::Controller._cache.expire_key_for(options, controller_name, true) do |key, match|
    if match
      files = Dir.glob(config_dir / "#{key}*")
    else
      extension = options[:extension] || DEFAULT_PAGE_EXTENSION
      files = config_dir / "#{key}.#{extension}"
    end
    FileUtils.rm_rf(files)
  end
  true
end