2011-11-14 2 views
0

저는 앱을 가지고 있으며 페이지의 일부분을 캐싱하고 싶습니다.이 작업을 수행하는 방법에 대해 많이 읽었습니다.ruby ​​on rails 3.1 프래그먼트 캐싱

프래그먼트 캐싱이 내 프로젝트에서 가장 좋은 방법이라는 것을 알고 있지만 이것을 구현하는 방법을 배우기위한 간단한 예제를 찾을 수 없습니다.

자동 실행으로 조각 캐시를 사용하고 싶습니다.

<% cache(:action => 'recent', :action_suffix => 'all_products') do %> 
     All available products: 
     <% Product.all.each do |p| %> 
     <%= link_to p.name, product_url(p) %> 
     <% end %> 
    <% end %> 

어디에서 자동 완성을 설정합니까? 주위에 어떤 예제? 내가 어떻게 할 수 있니? 제품 모델에서

답변

2

after_save :expire_caches 
    after_destroy :expire_caches 

    # can't do this in a sweeper since there isn't a controller involved 
    def expire_caches 
     ActionController::Base.cache_store.delete_matched(%r{product\?for=\d+&fragment=products}) 
처럼 뭔가를 할 수