putyourlightson / craft-blitz

Intelligent static page caching for creating lightning-fast sites with Craft CMS.
https://putyourlightson.com/plugins/blitz
Other
149 stars 36 forks source link

Expired entry and source tags #267

Closed LouisCuvelier closed 3 years ago

LouisCuvelier commented 4 years ago

Question

I've multiple "job offer" entries. Each entry has an expiry date. So, on each entry, I added this :

{% do craft.blitz.options({
  expiryDate: entry.expiryDate
}) %}

And I set a cron job to clear the cache. Working great !

Also, I display all these "job offers" in an "index" page. So I added this to the "index" page :

{% do craft.blitz.options.tags('sectionId:' ~ craft.entries.section('jobOffers').sectionId[0]) %}

But, when a job offer expired, the "index" page's cache is not cleared. "Index" page's cache refresh is working fine when the expiration date has not passed or when I schedule the entry. Even after using "Refresh expired cache" utility, "index" page's cache is not refreshed.

Am I missing something ?

bencroker commented 4 years ago

Elements will be assigned an expiry date when cached, so there's no need to manually do that.

Which cron job do you have in place in with what frequency is it being executed?

LouisCuvelier commented 4 years ago

Elements will be assigned an expiry date when cached, so there's no need to manually do that.

Ok I removed it.

I'm using this one :

5 0 * * * /usr/bin/php /path/to/craft blitz/cache/refresh-expired
bencroker commented 4 years ago

Ok so that will be run once per day at 00:05 (https://crontab.guru/#50__*). You probably will want to run it at least hourly, if not more frequently, as per the docs (https://putyourlightson.com/plugins/blitz#cron-jobs).

// Refresh expired cache every hour at 5 minutes past the hour.
5 * * * * /usr/bin/php /path/to/craft blitz/cache/refresh-expired
LouisCuvelier commented 4 years ago

The cron job is not the problem. It works and I want it like this.

The problem comes from the source tags. When an entry (e.g. entry A) that is expired has it cache cleaned, pages with the source tags linked to "entry A" are not cleaned.

bencroker commented 4 years ago

Got it, will look into it.

bencroker commented 3 years ago

I'm unable to replicate this issue. If your entries listing page contains an entry that expires, the listing page should be refreshed, without needing the source tag (assuming the cacheElements config setting is not set to false).

Can you please retest with the latest version of Blitz and let me know if there is any change?

LouisCuvelier commented 3 years ago

I've updated the plugin and the config file. But, here's a new problem : When I save the entry and set an expiration date, entry's cache is not cleared even by using the CLI command or button in CP. I've to re-save the entry (after expiration date) to get it cleared.

Here's my config file :

<?php
/**
 * @copyright Copyright (c) PutYourLightsOn
 */

/**
 * Blitz config.php
 *
 * This file exists only as a template for the Blitz settings.
 * It does nothing on its own.
 *
 * Don't edit this file, instead copy it to 'craft/config' as 'blitz.php'
 * and make your changes there to override default settings.
 *
 * Once copied to 'craft/config', this file will be multi-environment aware as
 * well, so you can have different settings groups for each environment, just as
 * you do for 'general.php'
 */

return [
    '*' => [
        // With this setting enabled, Blitz will log detailed messages to `storage/logs/blitz.php`.
        'debug' => false,
        // With this setting enabled, Blitz will begin caching pages according to the included/excluded URI patterns. Disable this setting to prevent Blitz from caching any new pages.
        'cachingEnabled' => true,
        // The URI patterns to include in caching. Set `siteId` to a blank string to indicate all sites.
        'includedUriPatterns' => [
            [
                'siteId' => '',
                'uriPattern' => '.*'
            ]
        ],
        // The URI patterns to exclude from caching (overrides any matching patterns to include). Set `siteId` to a blank string to indicate all sites.
        'excludedUriPatterns' => [],
        // The storage type to use.
        'cacheStorageType' =>
            'putyourlightson\blitz\drivers\storage\FileStorage',
        //  The storage settings.
        'cacheStorageSettings' => [
            'folderPath' => '@webroot/cache/blitz',
            'createGzipFiles' => true,
            'countCachedFiles' => true
        ],
        // The storage type classes to add to the plugin’s default storage types.
        'cacheStorageTypes' => [],
        // The warmer type to use.
        'cacheWarmerType' =>
            'putyourlightson\blitz\drivers\warmers\GuzzleWarmer',
        // The warmer settings.
        'cacheWarmerSettings' => ['concurrency' => 3],
        // The warmer type classes to add to the plugin’s default warmer types.
        'cacheWarmerTypes' => [],
        // Custom site URIs to warm when either a site or the entire cache is warmed.
        'customSiteUris' => [],
        // The purger type to use.
        'cachePurgerType' =>
            'putyourlightson\blitz\drivers\purgers\CloudflarePurger',
        // The purger settings.
        'cachePurgerSettings' => [
            'zoneIds' => [
                "" => [
                    'zoneId' => ''
                ]
            ],
            'email' => '',
            'apiKey' => '',
            'warmCacheDelay' => 5
        ],
        // The purger type classes to add to the plugin’s default purger types.
        'cachePurgerTypes' => [],
        // The deployer type to use.
        //'deployerType' => 'putyourlightson\blitz\drivers\deployers\GitDeployer',
        // The deployer settings.
        'deployerSettings' => [],
        // The deployer type classes to add to the plugin’s default deployer types.
        'deployerTypes' => [],
        // Whether the cache should automatically be cleared when elements are updated.
        'clearCacheAutomatically' => true,
        // Whether the cache should automatically be warmed after clearing.
        'warmCacheAutomatically' => false,
        // Whether the cache should automatically be refreshed after a global set is updated.
        'refreshCacheAutomaticallyForGlobals' => true,
        // Whether the cache should be refreshed when an element is saved but unchanged.
        'refreshCacheWhenElementSavedUnchanged' => false,
        // Whether the cache should be refreshed when an element is saved but not live.
        'refreshCacheWhenElementSavedNotLive' => false,
        // Whether URLs with query strings should cached and how.
        // 0: Do not cache URLs with query strings
        // 1: Cache URLs with query strings as unique pages
        // 2: Cache URLs with query strings as the same page
        'queryStringCaching' => 0,
        // The query string parameters to exclude when determining if and how a page should be cached.
        'excludedQueryStringParams' => ['gclid', 'fbclid'],
        // An API key that can be used to clear, flush, warm, or refresh expired cache through a URL (min. 16 characters).
        'apiKey' => '',
        // A path to the `bin` folder that should be forced.
        'binPath' => '',
        // Whether elements should be cached in the database.
        'cacheElements' => true,
        // Whether element queries should be cached in the database.
        'cacheElementQueries' => true,
        // The amount of time after which the cache should expire (if not 0). See [[ConfigHelper::durationInSeconds()]] for a list of supported value types.
        'cacheDuration' => 0,
        // Element types that should not be cached.
        'nonCacheableElementTypes' => [
            'craft\elements\GlobalSet',
            //    'craft\elements\MatrixBlock',
            'benf\neo\elements\Block',
            'putyourlightson\campaign\elements\ContactElement'
        ],
        // The integrations to initialise.
        'integrations' => [
            'putyourlightson\blitz\drivers\integrations\FeedMeIntegration',
            'putyourlightson\blitz\drivers\integrations\SeomaticIntegration'
        ],
        // The value to send in the cache control header.
        'cacheControlHeader' => 'public, s-maxage=31536000, max-age=0',
        // Whether an `X-Powered-By: Blitz` header should be sent.
        'sendPoweredByHeader' => false,
        // Whether the timestamp and served by comments should be appended to the cached output.
        'outputComments' => false,
        // The priority to give the refresh cache job (the lower number the number, the higher the priority). Set to `null` to inherit the default priority.
        'refreshCacheJobPriority' => 10,
        // The priority to give driver jobs (the lower number the number, the higher the priority). Set to `null` to inherit the default priority.
        'driverJobPriority' => 100,
        // The time in seconds to wait for mutex locks to be released.
        'mutexTimeout' => 1,
        // The paths to executable shell commands.
        //'commands' => [
        //    'git' => '/usr/bin/git',
        //],

        // The name of the JavaScript event that will trigger a script inject.
        'injectScriptEvent' => 'DOMContentLoaded'
    ],
    'dev' => [
        'debug' => true,
        'cachingEnabled' => false
    ],
    'staging' => [
        'debug' => true,
    ],
    'production' => [
        'warmCacheAutomatically' => true
    ]
];

Any idea ?

bencroker commented 3 years ago

Managed to track it down and fixed in https://github.com/putyourlightson/craft-blitz/commit/75468bdd59c40615e69ab356fe5621069010bde9 for the next release, thanks!

bencroker commented 3 years ago

Released in 3.7.0.