hobo? or are the pages and dryml to dynamic to make any sense in
running memcache?
Discussion
- You can use standard rails caching with hobo. Including using memcache with them. Which makes for a nice way to implement caching, add the updated_at to the memcache key name. If the model changes, the cache automatically gets expired. Well, when the memory is needed it expires keys based on last access.
- Can you show an example of how to use this?
- I'm working on a recipe for this but for now. Install a memcached server (specific to your OS). In `config/environment.rb` add `config.cache_store = :mem_cache_store` in the `config` block should work in rails 2.2 and above at least.
For what I'm saying about automatic 'expiration' you'd use a key like so:
Rails.cache.write post.typed_id + post.updated_at.to_i.to_s, some_expensive_to_compute_variable
or in the view with fragment caching
<extend tag="card" for="Post">
<% cache(:key => ['card',this.typed_id, this.updated_at].join(':')) do %>
<old-card />
<% end %>
</extend>
Notice that fragments can be set on tags in the application controller and not just in the end view.
Since this fragment's key is dependent on updated_at time, any changes to the post, will request a different key and thus generate a new card. The old key (old card) will stay in memory but not be called. If memory gets full, or with the keys expiration, the old key value will be dropped as it shouldn't have been used recently. This is a neat technique and does make for less outdated hits. However, remember that if, in this example, a post card is dependent on some association, like an author, and that association is updated the post will not be updated at the same time.
Standard caching warnings apply and if you're unfamiliar with rails caching you might want to check out some of these sites. A word of warning, there's a lot of old info out about memcache and rails and much of it doesn't apply or will lead you to installing outdated/unnecessary gems.
* http://guides.rubyonrails.org/caching_with_rails.html
* http://www.scribd.com/doc/2203398/Scaling-Rails-with-memcached
* if you're using heroku, http://docs.heroku.com/memcache - Thanks much. Will check out these sites.
Owen
