Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails 3 Action Sweeper on Heroku
config.active_record.observers = :post_sweeper
class ApplicationController < ActionController::Base
protect_from_forgery
cache_sweeper :post_sweeper
end
gem 'memcachier'
gem 'dalli'
class PostSweeper < ActionController::Caching::Sweeper
observe Post
def after_save(post)
expire_cache_for_post_index
end
private
def expire_cache_for_post_index
cache_key = "views/#{request.host_with_port}/posts"
Rails.cache.delete(cache_key)
end
end
class PostsController < ApplicationController
caches_action :index
def index
@posts = Post.published
end
def show
@post = Post.find(params[:id])
end
end
config.cache_store = :dalli_store
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.