2011-08-22 15 views
7

私のアプリケーションでアクションキャッシュが期限切れになる問題があります。ここでカスタムcache_pathを使用してアクションキャッシュを期限切れにする

は私のコントローラである:

class ToplistsController < ApplicationController 
    caches_action :songs, cache_path: :custom_cache_path.to_proc 

    def custom_cache_path 
    "#{params[:when]}-#{params[:what]}-#{params[:controller]}-#{params[:action]}" 
    end 

    def songs 
    # ... 
    end 
end 

私は何とかカスタムキャッシュパスをリセットできるようにする必要がありますが、私はどのように把握することはできません。

私はすでにthis techniqueを使ってみましたが、成功しませんでした。私のキャッシュエンジンであるDalliはregexp matcherをサポートしていないようです。

このコードを使用しようとしたとき、私はこのエラーを取得しています:

expire_fragment(/songs/)

ActiveSupport::Cache::DalliStore does not support delete_matched

私はデバッグのために、コード行を使用しようとしたが、それは無視されています。

before_filter only: [:songs] 
    expire_fragment(custom_cache_path) 
end 

私はRails 3.1.0.rc6、Dalli 1.0.5、およびRuby 1.9.2を使用しています。

+1

あなたはdallicacheで正規表現を使用しています:https://github.com/defconomicron/dalli-store-extensions –

+0

私はそれを試してみます、ありがとう。 – Oleander

答えて

0

before_filterブロックはアクションキャッシュの2倍には無視されました。
解決策は、代わりにフラグメントキャッシュを使用することです。

# Controller 
class ToplistsController < ApplicationController 
    helper_method :custom_cache_path 

    before_filter only: [:songs] 
    if params[:reset_cache] 
     expire_fragment(custom_cache_path) 
    end 
    end 

    def custom_cache_path 
    "#{params[:when]}-#{params[:what]}-#{params[:controller]}-#{params[:action]}" 
    end 

    def songs 
    # ... 
    end 
end 

# View 

<%= cache custom_cache_path do %> 
    Content that should be cached 
<% end %> 
0

解決策hereをチェックしたい場合もあります。彼のアプローチでは、余分なパラメータでアクションを期限切れにすることができます。

関連する問題