Commit 3c4554f5dce32c966a2bc375b5779e6a9d1bbd01

Authored by Daniela Feitosa
1 parent 6e085769

Replacing Regexp by string on expiring blocks caches

From: http://apidock.com/rails/v2.3.2/ActionController/Caching/Fragments/expire_fragment

Regexp - Will remove any fragment that matches, so %r{pages/\d*/notes} might remove all notes. Make sure you don’t use
anchors in the regex (^ or $) because the actual filename matched looks like ./cache/filename/path.cache. Note: Regexp
expiration is only supported on caches that can iterate over all keys (unlike memcached).
app/models/recent_documents_block.rb
... ... @@ -32,8 +32,4 @@ class RecentDocumentsBlock < Block
32 32 end
33 33 end
34 34  
35   - def timeout
36   - 2.months
37   - end
38   -
39 35 end
... ...
app/sweepers/block_sweeper.rb
... ... @@ -5,15 +5,14 @@ class BlockSweeper < ActiveRecord::Observer
5 5 class << self
6 6 include SweeperHelper
7 7  
8   - def cache_key_regex(block)
  8 + # Expire block's all languages cache
  9 + def expire_block(block)
9 10 regex = '-[a-z]*$'
10 11 clean_ck = block.cache_key.gsub(/#{regex}/,'')
11   - %r{#{clean_ck+regex}}
12   - end
13 12  
14   - # Expire block's all languages cache
15   - def expire_block(block)
16   - expire_timeout_fragment(cache_key_regex(block))
  13 + Noosfero.locales.keys.each do |locale|
  14 + expire_timeout_fragment("#{clean_ck}-#{locale}")
  15 + end
17 16 end
18 17  
19 18 def expire_blocks(blocks)
... ...