{% cache %} always creates new cache data, never uses existing cached data Why would the {% cache %} tag be storing a new cache every time the page loads (instead of just loading the existing cache)?

Unless I'm misunderstanding how caching works, the system should never record duplicate cache keys, correct?



Despite the data apparently getting cached, the page never feels like it's pulling from cache. Every page load feels long and sluggish.



UPDATE:

I've done some additional testing, and was able to get the caching to perform as expected. Here's what changed...

In my original version, I was caching a giant chunk of the template. This included the large database query (100+ records with 100+ fields), some Twig-side data manipulation, and the entire HTML portion of the template. Within the HTML, I am looping through those records and rendering a chunk of HTML for each.

In the new version, I am only caching the HTML loop. This is making a huge difference, bringing the page load time from ~15 seconds to ~1 second. 

What I've found...

It appears that the offending line which was causing multiple cache keys to be generated is this one:

{% set entries = craft.entries.section('mySection').type('myType').limit(null).find %}


I still don't know why, and would appreciate an explanation if anyone knows!
Update:

This has been fixed for the next (post 2.4.2725) release.



Turns out there is a bug in Craft where if you put cache tags around code that doesn't actually output anything, then duplicate keys get created in the craft_templatecaches table.

No workaround for it yet (other than to make sure you don't cache an empty string), but it's been logged as a bug.