Created
February 18, 2009 18:29
-
-
Save Gregg/66462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To configure memcached to be used | |
# /config/environment.rb | |
config.cache_store = :mem_cache_store | |
# Object Store cache commands | |
Rails.cache.read | |
Rails.cache.write | |
Rails.cache.fetch | |
Rails.cache.delete | |
Rails.cache.exist? | |
Rails.cache.increment | |
Rails.cache.decrement | |
Rails.cache.clear | |
# Example of using expires_in | |
def self.recent | |
Rails.cache.fetch("recent_posts", :expires_in => 30.minutes) do | |
self.find(:all, :limit => 10) | |
end | |
end | |
# Using cache_key properly to give good cache keys | |
<% cache(post) do %> | |
<!-- Data related to this post --> | |
<% end %> | |
# A more realistic cache key | |
<% cache([post, user, "sidebar"]) do %> | |
<!-- Data related to this user and this post --> | |
<% end %> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment