How does key-based caching work?
- by Dominic Santos
I recently read an article on the 37Signals blog and I'm left wondering how it is that they get the cache key.
It's all well and good having a cache key that includes the object's timestamp (this means that when you update the object the cache will be invalidated); but how do you then use the cache key in a template without causing a DB hit for the very object that you are trying to fetch from the cache.
Specifically, how does this affect One to Many relations where you are rendering a Post's Comments for example.
Example in Django:
{% for comment in post.comments.all %}
{% cache comment.pk comment.modified %}
<p>{{ post.body }}</p>
{% endcache %}
{% endfor %}
Is caching in Rails different to just requests to memcached for example (I know that they convert your cache key to something different). Do they also cache the cache key?