2011-08-22 10 views
7

내 응용 프로그램에서 작업 캐시가 만료되는 데 문제가 있습니다.custom 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 블록은 작업 캐시의 듀오에서 무시되었습니다.
해결책은 단편 캐시를 대신 사용하는 것입니다.

# 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 솔루션을 확인하시기 바랍니다. 접근 방식을 사용하면 추가 매개 변수로 작업을 종료 할 수 있습니다.

관련 문제