Skip to content

Instantly share code, notes, and snippets.

@munazo
Forked from bostonaholic/Gemfile
Created December 25, 2013 13:00
Show Gist options
  • Select an option

  • Save munazo/8123030 to your computer and use it in GitHub Desktop.

Select an option

Save munazo/8123030 to your computer and use it in GitHub Desktop.
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