How does key-based caching work?

Posted by Dominic Santos on Programmers See other posts from Programmers or by Dominic Santos
Published on 2012-03-02T10:43:52Z Indexed on 2012/04/07 23:43 UTC
Read the original article Hit count: 437

Filed under:
|
|

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?

© Programmers or respective owner

Related posts about python

Related posts about django