Answers.Body: <p>As suggested by Fred, using the <code>{% cache globally using key craft.request.path %}</code> trick from <a href="https://craftcms.stackexchange.com/a/8335/342">https://craftcms.stackexchange.com/a/8335/342</a> gets rid of almost all duplicates!</p>
  
  <p>But for the last few I notice that the duplicates all expire within seconds of each other, maybe this is an instance of <a href="https://en.wikipedia.org/wiki/Cache_stampede" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Cache_stampede</a> ? </p>
  
  <p>I.e. several clients request the pages "simultaneously" and the page is rendered several times, and each version is cached? </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-09T12:29:48.363Z
Answers.LastActivityDate: 2015-09-09T12:29:48.363Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: gromgull
Body: <p>We have a site where we use lots of <code>{% cache %}</code> tags. </p>
  
  <p>Now we almost constantly have a "cleaning template cache" task running, and they often get stuck. </p>
  
  <p>Manual DB intervention and resetting the stuck task to status <code>pending</code>, will sometimes make it move again. </p>
  
  <p>I've tried the various solution here, but nothing helps: <a href="https://craftcms.stackexchange.com/questions/8237/deletestaletemplatecaches-job-getting-stuck">DeleteStaleTemplateCaches job getting stuck</a></p>
  
  <p>Also - there are no error entries in craft.log or phperrors.log when it gets stuck. </p>
  
  <p>Looking at the <code>craft_templatecaches</code> table I find lots of duplicate looking entries: </p>
  
  <pre><code>select id,locale, cacheKey, expiryDate, path from craft_templatecaches;
  
  ...
  | 685607 | nb     | zDzBdD8bc1y4pf9Sx2HFyL3i24YypSp2sAq5 | 2015-09-08 08:23:21 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  | 685610 | nb     | TMz4eh7FPiINSUixwkpXb0SlkHnZ3b5TSgXm | 2015-09-08 08:23:22 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  | 685611 | nb     | HgLIHHgf56nM1ggOdTmaLlaylu5JeOeM1dNm | 2015-09-08 08:23:23 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  | 685612 | nb     | SLHUKfUz2fF5Jmpy0kWPpvMxFBHH8PvlVJEt | 2015-09-08 08:23:25 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  | 685614 | nb     | oEU6fe1tGc7MdI8WSQIXsf2wZZd9qmXG8P9H | 2015-09-08 08:23:26 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  ...
  </code></pre>
  
  <p>Is this normal? </p>
  
  <p>Anything else I can do to debug why the task gets stuck? </p>
  
  <hr>
  
  <p>Update: </p>
  
  <p>Using keyed and global caching reduced the size of the <code>craft_templatecaches</code> table from ~20k rows to ~300. However, this did not stop the task getting stuck. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-08T12:35:19.023Z
Comments.Text: You might want to use a key on those cache tags. It looks like it's always creating new caches: http://craftcms.stackexchange.com/questions/7096/cache-always-creates-new-cache-data-never-uses-existing-cached-data
Comments.UserDisplayName: Fred Carlsen
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-08T15:29:20.377Z
Comments.Text: Also take a look at http://buildwithcraft.com/help/stuck-tasks
Comments.UserDisplayName: Luke Holder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-01T01:50:39.183Z
Comments.Text: Possible duplicate of [Long 'Deleting stale template caches'](http://craftcms.stackexchange.com/questions/2059/long-deleting-stale-template-caches)
Comments.UserDisplayName: Simon East
Tags: <cache><caching>
Title: Massive template cache cleaning tasks always get stuck
ThreadText: # Massive template cache cleaning tasks always get stuck
  
  (Asked by: username_0 on 2015-09-08)
  
  We have a site where we use lots of `{% cache %}` tags.
  
  Now we almost constantly have a "cleaning template cache" task running, and they often get stuck.
  
  Manual DB intervention and resetting the stuck task to status `pending`, will sometimes make it move again.
  
  I've tried the various solution here, but nothing helps: [DeleteStaleTemplateCaches job getting stuck](https://craftcms.stackexchange.com/questions/8237/deletestaletemplatecaches-job-getting-stuck)
  
  Also - there are no error entries in craft.log or phperrors.log when it gets stuck.
  
  Looking at the `craft_templatecaches` table I find lots of duplicate looking entries:
  
  ```
  select id,locale, cacheKey, expiryDate, path from craft_templatecaches;
  
  ...
  | 685607 | nb     | zDzBdD8bc1y4pf9Sx2HFyL3i24YypSp2sAq5 | 2015-09-08 08:23:21 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  | 685610 | nb     | TMz4eh7FPiINSUixwkpXb0SlkHnZ3b5TSgXm | 2015-09-08 08:23:22 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  | 685611 | nb     | HgLIHHgf56nM1ggOdTmaLlaylu5JeOeM1dNm | 2015-09-08 08:23:23 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  | 685612 | nb     | SLHUKfUz2fF5Jmpy0kWPpvMxFBHH8PvlVJEt | 2015-09-08 08:23:25 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  | 685614 | nb     | oEU6fe1tGc7MdI8WSQIXsf2wZZd9qmXG8P9H | 2015-09-08 08:23:26 | site:kompetansetilbud/ny-i-hr-rollen-i-trondheim-10013                                   |
  ...
  
  ```
  
  Is this normal?
  
  Anything else I can do to debug why the task gets stuck?
  
  ---
  
  Update:
  
  Using keyed and global caching reduced the size of the `craft_templatecaches` table from ~20k rows to ~300. However, this did not stop the task getting stuck.
  
  **Tags:** cache, caching
  
  > **Comments:**
  > **username_1**: You might want to use a key on those cache tags. It looks like it's always creating new caches: http://craftcms.stackexchange.com/questions/7096/cache-always-creates-new-cache-data-never-uses-existing-cached-data  
  > **username_2**: Also take a look at http://buildwithcraft.com/help/stuck-tasks  
  > **username_3**: Possible duplicate of [Long 'Deleting stale template caches'](http://craftcms.stackexchange.com/questions/2059/long-deleting-stale-template-caches)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-09-09. Score: 1
  
  As suggested by username_1, using the `{% cache globally using key craft.request.path %}` trick from <https://craftcms.stackexchange.com/a/8335/342> gets rid of almost all duplicates!
  
  But for the last few I notice that the duplicates all expire within seconds of each other, maybe this is an instance of <https://en.wikipedia.org/wiki/Cache_stampede> ?
  
  I.e. several clients request the pages "simultaneously" and the page is rendered several times, and each version is cached?
  
  
  ---
  
  