Answers.Body: <p>I had a <code>{% cache %}</code> tag around my global <code>header</code> template, which is pulled in by every template, including the 404 template. Apparently Craft doesn't care if the 404 template is being called or not, if it sees a <code>{% cache %}</code> tag it's caching that content.</p>
  
  <p>The Wordpress and file extension paths are all from bots pinging the site trying to find a vulnerability, and every time those URLs threw a 404 a new cache record was created for the header. </p>
  
  <p>So I set a variable in my 404 template and checked if it was set in my header template before caching:</p>
  
  <p><strong>404.html</strong></p>
  
  <pre><code>{% extends 'layouts/_global' %}
  
  {% set fourohfour = true %}
  
  {% block pageBody %}
      &lt;h1&gt;404, yo.&lt;/h1&gt;
  {% endblock %}
  </code></pre>
  
  <p><strong>header.html</strong> (included in <code>layouts/_global</code>)</p>
  
  <pre><code>{% cache if fourohfour is not defined %}
      &lt;nav&gt;
          {% for page in craft.entries.section('Pages').level(1).all %}
              &lt;a href="{{ page.url }}"{% if craft.app.request.segment(1) == page.slug %} class="current"{% endif %}&gt;{{ page.title }}&lt;/a&gt;
          {% endfor %}
      &lt;/nav&gt;
  {% endcache %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-16T21:19:13.467Z
Answers.LastActivityDate: 2019-09-17T20:41:18.727Z
Answers.LastEditDate: 2019-09-17T20:41:18.727Z
Answers.UserDisplayName: kmgdev
Body: <p>I'm trying to figure out why I have so many template cache records and when I look in my database <code>templatecaches</code> table I'm seeing a bunch of rows being stored for paths that don't exist. For example there are a bunch of Wordpress-like paths that presumably a bot tried to hit:</p>
  
  <pre><code>site:wp-admin
  site:wp-content/themes/konzept/includes/uploadify/uploads/cache.php
  </code></pre>
  
  <p>Also a bunch of records with file extensions like <code>.zip</code> and <code>.rar</code>:</p>
  
  <pre><code>site:website.tar.gz
  site:website.rar
  site:webroot.zip
  </code></pre>
  
  <p>All of these paths should have thrown a 404 when the bogus URL was hit, and therefore should not have triggered a cache record to be created. Why am I getting all these junk cache records?</p>
  
Tags: <cache>
Title: Cache Records Being Stored for Invalid Paths
ThreadText: # Cache Records Being Stored for Invalid Paths
  
  (Asked by: username_0 on 2019-09-16)
  
  I'm trying to figure out why I have so many template cache records and when I look in my database `templatecaches` table I'm seeing a bunch of rows being stored for paths that don't exist. For example there are a bunch of Wordpress-like paths that presumably a bot tried to hit:
  
  ```
  site:wp-admin
  site:wp-content/themes/konzept/includes/uploadify/uploads/cache.php
  
  ```
  
  Also a bunch of records with file extensions like `.zip` and `.rar`:
  
  ```
  site:website.tar.gz
  site:website.rar
  site:webroot.zip
  
  ```
  
  All of these paths should have thrown a 404 when the bogus URL was hit, and therefore should not have triggered a cache record to be created. Why am I getting all these junk cache records?
  
  **Tags:** cache
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-09-16. Score: 1 | Accepted answer
  
  I had a `{% cache %}` tag around my global `header` template, which is pulled in by every template, including the 404 template. Apparently Craft doesn't care if the 404 template is being called or not, if it sees a `{% cache %}` tag it's caching that content.
  
  The Wordpress and file extension paths are all from bots pinging the site trying to find a vulnerability, and every time those URLs threw a 404 a new cache record was created for the header.
  
  So I set a variable in my 404 template and checked if it was set in my header template before caching:
  
  **404.html**
  
  ```
  {% extends 'layouts/_global' %}
  
  {% set fourohfour = true %}
  
  {% block pageBody %}
      <h1>404, yo.</h1>
  {% endblock %}
  
  ```
  
  **header.html** (included in `layouts/_global`)
  
  ```
  {% cache if fourohfour is not defined %}
      <nav>
          {% for page in craft.entries.section('Pages').level(1).all %}
              <a href="{{ page.url }}"{% if craft.app.request.segment(1) == page.slug %} class="current"{% endif %}>{{ page.title }}</a>
          {% endfor %}
      </nav>
  {% endcache %}
  
  ```
  
  
  ---
  
  