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

Set cache durations based on entries' expiry dates #11901

Merged

Conversation

brandonkelly
Copy link
Member

Description

When entries with expiry dates are fetched/referenced while element caching is active (e.g. for {% cache %} tags or GraphQL query caching), Craft will now keep track of the closest expiry date.

When cache info collection is complete, if the closest expiry date is closer to the current time than the cacheDuration config setting, the resulting cache will be set to expire on the expiry date, rather than the default cache duration.

A new craft\base\ExpirableElementInterface class has been added in case any other element types want to participate as well (e.g. Commerce products).

The old element cache tag-related methods on craft\services\Elements have been deprecated, and replaced by new “info” methods:

Deprecated Method New Method
getIsCollectingCacheTags() getIsCollectingCacheInfo()
startCollectingCacheTags() startCollectingCacheInfo()
stopCollectingCacheTags() stopCollectingCacheInfo()

Note
stopCollectingCacheInfo()’s return data is different from stopCollectingCacheTags(). If no cache tags were registered while the element cache collection was active, it will return [null, null]. Otherwise it will return an array that contains a TagDependency object and either an integer or null, which represents the max recommended cache duration if known.

If any plugins are using element caching for their own purposes, they’re encouraged to start calling the new craft\services\Elements methods whenever they’re comfortable requiring craftcms/cms: ^4.3.0 or later.

Related

@brandonkelly brandonkelly requested a review from a team as a code owner September 8, 2022 03:05
@linear
Copy link

linear bot commented Sep 8, 2022

[ci skip]
@brandonkelly brandonkelly merged commit 02849b5 into 4.3 Sep 8, 2022
@brandonkelly brandonkelly deleted the feature/dev-988-set-cache-durations-based-on-entries branch September 8, 2022 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant