rails expiring cache
Posted
by ash34
on Stack Overflow
See other posts from Stack Overflow
or by ash34
Published on 2010-06-15T07:28:58Z
Indexed on
2010/06/15
7:32 UTC
Read the original article
Hit count: 273
ruby-on-rails
Hi,
I entered some products data into a table using a migration. I need to expire the page and fragment cache when I update, add, delete products from this table. I created a sweeper for this.
class ProductSweeper < ActionController::Caching::Sweeper
observe Product
def after_create
expire_cache
end
def after_save
expire_cache
end
def after_update
expire_cache
end
def after_destroy
expire_cache
end
private
def expire_cache
expire_page(:controller => 'ProductsController', :action => 'index')
expire_fragment 'listed_products'
end
end
Then in script/console I update the product name and saved. When I reload my app in the browser it still gives me a cache hit.
Cached fragment hit: views/listed_products (0.2ms)
Can someone tell me how to expire this cache. I will not be adding, updating, deleting products through a controller action.
thanks, ash
© Stack Overflow or respective owner