Skip to content

Instantly share code, notes, and snippets.

@evanwalsh
Created December 9, 2008 03:32
Show Gist options
  • Save evanwalsh/33747 to your computer and use it in GitHub Desktop.
Save evanwalsh/33747 to your computer and use it in GitHub Desktop.
# A model for Ruby on Rails that gets settings from a DB
# And it caches them! Success!
class Preference < ActiveRecord::Base
def self.get(name)
return Rails.cache.fetch(name) {
output = self.find_by_name!(name)
Rails.cache.write(name,output.value)
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment