Loading twitter status...
/ 06.Jul.2008
Rails has allowed you to do things like page caching and fragment caching for a while now but with Rails 2.1, they added a new cool feature for doing some more lower level things with cache. You can now cache pretty much anything you want, any way you want. It’s easy as pie too!
Rails.cache.fetch("my_caches_name", {:expires_in => 5.minutes}) { download_xml_file_from_web }
I’m using the above example in an application to cache an xml file from another website for 5 minutes. The expires_in option is only for if your using memcached as your cache store which I setup below in my config/development.rb..
config.cache_store = :mem_cache_store, '123.45.6.78:11211', {:namespace => 'myapp_cache'}
It’s that easy. I’m loving it. You can play around with the various settings. You can use a file store, memory store (which I think is default but won’t work well with multiple mongrels), drb store or the (imho, best option) memcached. There are other methods for Rails.cache that you can find here# in the documentation… Enjoy!
micro theme by seaofclouds, edited by me, and powered with Mephisto
Leave a Comment