Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created May 16, 2012 15:12
Show Gist options
  • Save jgaskins/2711095 to your computer and use it in GitHub Desktop.
Save jgaskins/2711095 to your computer and use it in GitHub Desktop.
Manual cache invalidation
class Article < ActiveRecord::Base
def publish
self.published_at = Time.current
saved = save
Rails.cache.clear("published_articles")
saved
end
end
class ArticlesController < ApplicationController
def index
@articles = Rails.cache.fetch("published_articles") do
Article.published.all
end
end
end
@loveybot
Copy link

Yay Ruby!!

@loveybot
Copy link

Yay Ruby!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment