Skip to content

[FR] Cache clearing CLI and/or utility #136

@yoannisj

Description

@yoannisj

Description

It would be great to add a craft CLI command and/or a checkbox in the CP's clear-caches utility, to clear all element-api caches. This action could then be triggered on deployments and element change related events (save, publish, expire, etc.).

Currently, the only way to clear element-api caches reliably is to flush all data caches with Craft::$app->getCaches()->flush(), but this is a bit aggressive as it potentially clears cache entries from other plugins (and I believe as of Craft 3.5 also rendered template caches).

A less aggressive approach would be to clear the cache entry for a given element when it gets saved (probably also when an entry gets published or expires), as suggested here, but this won't work if an endpoint returns related element data (when the related element gets saved, getting the cache key for each and every endpoint where this element is included can quickly become quite tricky).

For this use case (not so uncommon in my own experience for what it's worth), I believe linking the element-api cache to element query caches (similar to how template caches are handled) would be the most efficient approach.

Relate issues #47, #55, #122

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions