Skip to content

Instantly share code, notes, and snippets.

@bostonaholic
Last active December 10, 2015 07:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bostonaholic/4400728 to your computer and use it in GitHub Desktop.
Save bostonaholic/4400728 to your computer and use it in GitHub Desktop.
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