1

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?

1

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 %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.