Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the cache regeneration behavior with refreshMode = 0? #755

Open
scandella opened this issue Jan 22, 2025 · 5 comments
Open

What is the cache regeneration behavior with refreshMode = 0? #755

scandella opened this issue Jan 22, 2025 · 5 comments
Labels
question Further information is requested

Comments

@scandella
Copy link

Support Request

Unexpected cache regeneration behavior with refreshMode = 0

Description

When using Blitz with refreshMode => 0 (Expire the cache, regenerate manually), I expect the cache to be regenerated only when:

  • The cache expires and the page is refreshed
  • A cron job triggers the regeneration

However, I've noticed that whenever an entry is saved, the entire cache is automatically regenerated, despite the setting suggesting manual regeneration only.

Expected Behavior

Cache regeneration should only happen through manual intervention or cron jobs
No automatic regeneration of the entire cache on entry saves

Question

Is this the intended behavior with refreshMode => 0?
If not, how can I achieve the expected behavior described above?

Current Configuration

php
'blitz' => [
    'cacheEnabled' => true,
    'refreshMode' => 0,
],

Environment

Craft CMS version: Craft Pro 5.5.10
Blitz plugin version: 5.9.9
PHP version: 8.2.18

Plugin Version

5.9.9

@scandella scandella added the question Further information is requested label Jan 22, 2025
@bencroker
Copy link
Collaborator

However, I've noticed that whenever an entry is saved, the entire cache is automatically regenerated, despite the setting suggesting manual regeneration only.

This is not the expected behaviour when the refresh mode is set to Expire the cache, regenerate manually or organically. What exactly are you seeing that tells you the cache is being regenerated?

@scandella
Copy link
Author

When a entry is created or saved, the cache is regenerated for some elements.
Image

Application Info

  • PHP version: 8.2.18
  • Craft edition & version: Pro 5.5.10
  • Database driver & version: MariaDB 10.5.26

Installed Plugins

  • Blitz: 5.9.9
  • Child Me!: 2.2.3
  • CKEditor: 4.4.0
  • Default Dashboard: 3.0.1
  • Do It Yourself widget: 4.1.1
  • Elements Panel: 3.0.0
  • Feed Me: 6.6.1
  • Field Manager: 4.0.3
  • LJ Dynamic Fields: 5.0.1
  • LJ Range Slider: 5.0.0
  • Preparse: 3.0.0-alpha.2

Loaded Modules

  • sempe-art: modules\sempeart\SempeArt
  • codeeditor: nystudio107\codeeditor\CodeEditor
  • sprig-core: putyourlightson\sprig\Sprig
  • verbb-base: verbb\base\Base

Blitz Plugin Settings

{
    "debug": false,
    "hintsEnabled": true,
    "cachingEnabled": true,
    "refreshCacheEnabled": true,
    "refreshMode": 0,
    "includedUriPatterns": [
        {
            "siteId": "",
            "uriPattern": "inventaire",
            "enabled": true
        },
        {
            "siteId": "",
            "uriPattern": "area",
            "enabled": true
        }
    ],
    "excludedUriPatterns": [],
    "cacheStorageType": "putyourlightson\\blitz\\drivers\\storage\\FileStorage",
    "cacheStorageSettings": {
        "folderPath": "@webroot\/cache\/blitz",
        "compressCachedValues": ""
    },
    "cacheStorageTypes": [],
    "cacheGeneratorType": "putyourlightson\\blitz\\drivers\\generators\\HttpGenerator",
    "cacheGeneratorSettings": {
        "concurrency": "3"
    },
    "cacheGeneratorTypes": [],
    "customSiteUris": [],
    "cachePurgerType": "putyourlightson\\blitz\\drivers\\purgers\\DummyPurger",
    "cachePurgerSettings": [],
    "cachePurgerTypes": [],
    "deployerType": "putyourlightson\\blitz\\drivers\\deployers\\DummyDeployer",
    "deployerSettings": [],
    "deployerTypes": [],
    "ssiEnabled": false,
    "ssiTagFormat": "<!--#include virtual=\"{uri}\" -->",
    "detectSsiEnabled": true,
    "esiEnabled": false,
    "onlyCacheLowercaseUris": false,
    "queryStringCaching": 1,
    "includedQueryStringParams": [
        {
            "enabled": "1",
            "queryStringParam": ".*"
        }
    ],
    "excludedQueryStringParams": [
        {
            "enabled": "1",
            "queryStringParam": "gclid"
        },
        {
            "enabled": "1",
            "queryStringParam": "fbclid"
        }
    ],
    "apiKey": "",
    "generatePagesWithQueryStringParams": false,
    "purgeAssetImagesWhenChanged": true,
    "refreshCacheAutomaticallyForGlobals": true,
    "refreshCacheWhenElementMovedInStructure": true,
    "refreshCacheWhenElementSavedUnchanged": false,
    "refreshCacheWhenElementSavedNotLive": false,
    "cacheNonHtmlResponses": false,
    "trackElements": true,
    "trackElementQueries": true,
    "excludedTrackedElementQueryParams": [],
    "cacheDuration": null,
    "nonCacheableElementTypes": [],
    "sourceIdAttributes": [],
    "liveStatuses": [],
    "integrations": [
        "putyourlightson\\blitz\\drivers\\integrations\\CommerceIntegration",
        "putyourlightson\\blitz\\drivers\\integrations\\SeomaticIntegration"
    ],
    "defaultCacheControlHeader": "no-store",
    "cacheControlHeader": "public, s-maxage=31536000, max-age=0",
    "cacheControlHeaderExpired": "public, s-maxage=5, max-age=0",
    "sendPoweredByHeader": true,
    "outputComments": true,
    "refreshCacheJobPriority": 10,
    "driverJobBatchSize": 100,
    "driverJobPriority": 100,
    "queueJobTtr": 300,
    "maxRetryAttempts": 10,
    "maxUriLength": 255,
    "mutexTimeout": 1,
    "commands": [],
    "injectScriptEvent": "DOMContentLoaded",
    "injectScriptPosition": 3
}

Recommendations

  • ❌ Image transforms are configured not to be generated before page load.
  • ❌ Queue jobs are configured to run automatically via web requests.
  • ❌ The blitz/cache/refresh-expired console command has not been executed within the past 24 hours.
  • ✅ Blitz is configured not to refresh cached pages when an element is saved but unchanged.
  • ✅ Blitz is configured not to refresh cached pages when an element is saved but not live.
  • ✅ No globals exist.
  • ✅ The @web alias is explicitly defined.
  • ✅ The Blitz Hints utility is not reporting any eager-loading opportunities.
  • ✅ The Async Queue plugin is not installed or enabled.

Site Tracking

  • Tracked Pages: 2
  • Tracked Includes: 0
  • Tracked Query String Params: 0
  • Tracked Elements: 8298
    • craft\elements\Entry: 3 611
    • craft\elements\Entry: 2 678
    • craft\elements\Tag: 1 629
    • craft\elements\Asset: 356
    • craft\elements\Category: 24
  • Tracked Element Queries: 6536
    • craft\elements\Entry: 6 500
    • craft\elements\Asset: 18
    • craft\elements\Tag: 16
    • craft\elements\Category: 2
  • Tracked Tags: 0

@bencroker
Copy link
Collaborator

That appears to be a Refresh cache job, not a Generate cache job. Refreshing the cache needs to take place regardless of the refresh mode selected. When using a refresh mode with Expire the cache in it, the queue job determines which cached pages need to be marked as expired.

Blitz appears to be tracking 6,500 entry queries, so there is likely an opportunity to optimise your templates. See https://putyourlightson.com/plugins/blitz#best-practices

@scandella
Copy link
Author

Thanks for the clarification.

Refreshing the cache needs to take place regardless of the refresh mode selected

If I understand correctly, whatever cache refresh mode is selected, a Refresh cache job is fired for every entry saved.

Blitz appears to be tracking 6,500 entry queries, so there is likely an opportunity to optimize your templates

I have precisely a page where all the entries are present.
So every time I save an entry, Blitz has to check every entry that is displayed in this cached page. Even if it does not generate the cached page, it checks the cache status of every entry for the cached page. Is that correct?
I was hoping that there is a refresh mode that does not check anything before being triggered by a cron job, allowing the entry to be modified without triggering some very long Blitz operations.

@bencroker
Copy link
Collaborator

If I understand correctly, whatever cache refresh mode is selected, a Refresh cache job is fired for every entry saved.

Correct.

So every time I save an entry, Blitz has to check every entry that is displayed in this cached page. Even if it does not generate the cached page, it checks the cache status of every entry for the cached page. Is that correct?

Yes, but it is the tracked entry queries that are generally the bottleneck. A well optimised site should have a few dozen queries at most, whereas your has 6,500. Use the Diagnostics utility to better understand how your site’s cached content is structured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants