Skip to content

[4.x]: Pending entries do not seem to clear template cache when published #16038

@mikesnoeren

Description

@mikesnoeren

What happened?

Description

In our project, we have entries with a future post date, which are saved in a "pending" state until the post date passes. The issue is that the template cache doesn't clear when the entry is published (i.e., when the post date is reached), but only when the entry is saved initially (while in "pending" state).

Steps to reproduce

  1. Create an entry with the post date set to a future time. (Note: The cache is cleared when the entry is saved in the "pending" state.)
  2. Visit the entry overview page, where all entries are displayed. (Note: The cache for this page is now rebuilt.)
  3. Wait until the post date passes, and the entry status changes to "live".
  4. Visit the overview page again, and see that the newly published entry is not listed.

(Optional additional steps):

  1. Create another entry with the post date set to a near-future time. (Note: The cache is cleared when this entry is saved.)
  2. Visit the overview page again, and see the earlier published entry is now listed. (Note: The cache clears due to the previous step.)
  3. Wait until the post date passes, and the entry status changes to "live".
  4. Visit the overview page again, and see the newly published entry is still not listed.

Expected behavior

The cache should be cleared when the entry is published (status changes to "live"), not when it's saved in the "pending" state.

Actual behavior

The cache is cleared when the entry is saved (while in "pending" state), not when it is published.

simplified code example

{% set cache_key = 'articles' %}
{% set query = craft.entries.section('articles').orderBy('postDate desc') %}

{% cache using key cache_key %}
    {% paginate query.limit(12) as pageInfo, items %}

    {% for item in items %}
        {# code for the individual items #}
    {% endfor %}

    {{ include('_inc/helpers/paginate.twig', {
        pageInfo: pageInfo
    }) }}
{% endcache %}

Craft CMS version

Craft Pro 4.12.6.1

PHP version

8.2.24

Operating system and version

Linux 6.11.5

Database type and version

MySQL 5.7.42

Image driver and version

GD 8.2.24

Installed plugins and versions

Name                            Handle                 Package Name                            Version  Installed  Enabled
------------------------------  ---------------------  --------------------------------------  -------  ---------  -------
CKEditor                        ckeditor               craftcms/ckeditor                       3.9.0    Yes        Yes    
Dashboard Begone                dashboard-begone       putyourlightson/craft-dashboard-begone  2.0.0    Yes        Yes    
DigitalOcean Spaces Filesystem  dospaces               vaersaagod/dospaces                     2.0.0    Yes        Yes    
Feed Me                         feed-me                craftcms/feed-me                        5.8.1    Yes        Yes    
Freeform                        freeform               solspace/craft-freeform                 5.6.4    Yes        Yes    
GPT Content Generator           gpt-content-generator  soerenmeier/gpt-content-generator       1.2.0    Yes        Yes    
Hyper                           hyper                  verbb/hyper                             1.3.2    Yes        Yes    
Kint                            kint                   verbb/kint                              3.1.1    Yes        Yes    
MatrixMate                      matrixmate             vaersaagod/matrixmate                   2.2.1    Yes        Yes    
Navigation                      navigation             verbb/navigation                        2.1.1    Yes        Yes    
Retour                          retour                 nystudio107/craft-retour                4.1.19   Yes        Yes    
SEOmatic                        seomatic               nystudio107/craft-seomatic              4.1.4    Yes        Yes    
Super Table                     super-table            verbb/super-table                       3.0.15   Yes        Yes    
Vite                            vite                   nystudio107/craft-vite                  4.0.10   Yes        Yes 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions