craft-blitz icon indicating copy to clipboard operation
craft-blitz copied to clipboard

Cache not clearing when new entry is created

Open markcoogan opened this issue 2 years ago • 7 comments

  • Create new entry in backend
  • Cache will be cleared automatically and front end will be updated
  • Craft CMS 3.5.17.1
  • Blitz 3.8.0

When creating a new entry, should Blitz clear the cache automatically? Currently, the cache only clears when updating an existing entry. The cache needs to cleared manually to have new entries appear at the moment.

markcoogan avatar Jul 07 '22 16:07 markcoogan

Blitz should clear the cache in that case. Please update to the latest version to ensure that this has not already been resolved.

bencroker avatar Jul 07 '22 16:07 bencroker

Hi again,

Sorry it took so long to get back. I've updated the plugin to the latest version and it's performing much better now, thanks.

There is still an issue around clearing the cache when a new entry is updated though. We still have to manually clear the cache to get updates to appear.

I can see that craft creates a Clear Cache job in the queue and I've installed the Async Queue plugin, but Craft never seems to get to the job. New jobs seem to get inserted ahead of it.

Is there a way to make clearing the blitz cache a priority job, or take it out of the queue altogether?

Update - I've updated an entry and let the jobs in the queue complete. The entry does not update on the front end and the cache has to be cleared manually to see the changes.

markcoogan avatar Aug 09 '22 10:08 markcoogan

There is, with the refreshCacheJobPriority config setting. https://github.com/putyourlightson/craft-blitz/blob/fe9da1b97363c1d713da2a347bbe70529feddcad/src/config.php#L198-L199

Can you run a test with a simple template that lists a few entries, by creating a new entry and checking if the cache is refreshed? This should work just fine out of the box.

bencroker avatar Aug 09 '22 17:08 bencroker

Hi Ben,

Thanks for your help. I've added the config value above and set it to 1, and I can see that the Refreshing Blitz Cache job is now the first job in the queue after creating a new entry and updating an existing one.

To test, I added a new entry and updated an existing one, waited for the queue to finish. Both items did not update on the site. When I checked Utilities > Blitz Cache, it listed the number of cached pages at 180 still. Should this be reset when the job finishes?

Manually clearing the cache got the changes to appear.

markcoogan avatar Aug 10 '22 09:08 markcoogan

Can you show me your simplified template code that you are testing with, as well as the plugin settings stored in config/project/project.yaml? Also the plugin version that you're running.

bencroker avatar Aug 10 '22 10:08 bencroker

Hi Ben,

The plugin version is: 3.8.0

The template code is:

{% extends "_layout" %}

{% block content %}

  {% set myEntryQuery = craft.entries()
  .section('news')
  .limit(10) %}

<section class="directoy-cards o-block--mb-50-80">
    <div class="grid-container">
        <div class="grid-x grid-margin-x">
          {% for entry in myEntryQuery %}
            <div class="cell large-4">

                    <div class="o-news-touchpoint">
                        <div class="o-events-touchpoint-content">
                            <h2>{{ entry.title }}</h2>
                        </div>
                    </div>

            </div>
          {% endfor %}
        </div>
    </div>
</section>

{% endblock content %}

In the project.yml for Blitz its:

blitz:
    edition: standard
    enabled: true
    licenseKey: K241CVTLI7L24DHHSAZHWMYX
    schemaVersion: 3.6.6
    settings:
      apiKey: ''
      cacheControlHeader: 'public, s-maxage=31536000, max-age=0'
      cacheDuration: null
      cacheElementQueries: true
      cacheElements: true
      cachePurgerType: putyourlightson\blitz\drivers\purgers\DummyPurger
      cacheStorageSettings:
        __assoc__:
          -
            - folderPath
            - '@webroot/cache/blitz'
          -
            - createGzipFiles
            - ''
          -
            - createBrotliFiles
            - ''
      cacheStorageType: putyourlightson\blitz\drivers\storage\FileStorage
      cacheWarmerSettings:
        __assoc__:
          -
            - concurrency
            - '3'
      cacheWarmerType: putyourlightson\blitz\drivers\warmers\GuzzleWarmer
      cachingEnabled: '1'
      clearCacheAutomatically: '1'
      customSiteUris: ''
      debug: false
      deployerType: putyourlightson\blitz\drivers\deployers\DummyDeployer
      driverJobPriority: 100
      excludedQueryStringParams:
        - gclid
        - fbclid
      excludedUriPatterns:
        -
          __assoc__:
            -
              - uriPattern
              - contact-us
        -
          __assoc__:
            -
              - uriPattern
              - 'search/results?q'
      includedUriPatterns:
        10:
          __assoc__:
            -
              - uriPattern
              - '.*'
        11:
          __assoc__:
            -
              - uriPattern
              - ''
      injectScriptEvent: DOMContentLoaded
      integrations:
        - putyourlightson\blitz\drivers\integrations\FeedMeIntegration
        - putyourlightson\blitz\drivers\integrations\SeomaticIntegration
      mutexTimeout: 1
      outputComments: true
      queryStringCaching: '0'
      refreshCacheAutomaticallyForGlobals: true
      refreshCacheJobPriority: 10
      refreshCacheWhenElementSavedNotLive: false
      refreshCacheWhenElementSavedUnchanged: false
      sendPoweredByHeader: true
      warmCacheAutomatically: ''

markcoogan avatar Aug 16 '22 09:08 markcoogan

Blitz is currently at version 3.12.5, you said you updated but you're still running 3.8.0. Can you please test again after updating?

bencroker avatar Aug 16 '22 14:08 bencroker

Closing due to inactivity.

bencroker avatar Oct 19 '22 18:10 bencroker