Cache Records Being Stored for Invalid Paths 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?
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 %}
    &lt;h1&gt;404, yo.&lt;/h1&gt;
{% endblock %}


header.html (included in layouts/_global)

{% 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 %}