My question is regarding template caching in Craft. I want to know when does Craft actually change the cache or delete old cache.
Let's say that I am caching a chunk that just displays the entry title. Does Craft detect this change when I reload the page and hence change the cache as well? I don't know if that makes sense.
Also, I wanted some insight into the cache structure. I was caching some chunks that displayed an entry's title, description etc. The code is something like this:
{% for document in resultset %}
{% cache using key document.entryId ~ "searchresult" %}
{% set entry = craft.entries.id( document.entryId )[0] %}
<div>{{ entry.title }}</div>
...
{% endcache %}
{% endfor %}
When I looked into the cache tables in the database it seems like the cache is associated with an entry using the entry id.
I wanted to know how Craft knows which entry this cache relates to since the key that I have passed could have been anything and I could have cached a category or something instead of an entry. I am very confused as to how this magic is occurring.