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

[4.x] Allow a custom static caching url store to be specified #9405

Conversation

ryanmitchell
Copy link
Contributor

@ryanmitchell ryanmitchell commented Jan 26, 2024

Static caching stores a cache of mapping of URLs to filenames in the Laravel cache, which is retrieved during invalidation.

However, if you have cleared your Laravel cache (eg artisan cache:clear), this mapping is lost, so no URLs are invalidated.

This PR provides a work around this behaviour by allowing a static_cache cache store to specified, which is then used for storing these urls. This wont be affected by the default cache:clear command, only by php artisan static:clear

Closes #7333

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than setting a path and making an explicit FileStore, I think it could be better to let you create a static_cache cache store, and use that if it exists. Like we do for the outpost:

private function cache()
{
if ($this->store) {
return $this->store;
}
try {
$store = Cache::store('outpost');
} catch (InvalidArgumentException $e) {
$store = Cache::store();
}
return $this->store = $store;
}

@ryanmitchell
Copy link
Contributor Author

Would that not be the same and remove everything during cache:clear ?

@jasonvarga
Copy link
Member

jasonvarga commented Jan 26, 2024

Nope. Only the default store is cleared during cache:clear. You can provide a specific store to the command.

@ryanmitchell
Copy link
Contributor Author

Ah cool. Didn’t know that. Thanks!

@ryanmitchell
Copy link
Contributor Author

I've updated that now. Would it make sense for me to PR a change to https://github.com/statamic/statamic/blob/4.x/config/cache.php to include a static_cache store so that the default behaviour is updated?

@jasonvarga
Copy link
Member

Would it make sense for me to PR a change to statamic/[email protected]/config/cache.php to include a static_cache store so that the default behaviour is updated

Yes. Make sure that the path is different from the file store - otherwise it will still be affected by cache:clear.

@jasonvarga jasonvarga merged commit 0da35cc into statamic:4.x Jan 29, 2024
19 checks passed
@ryanmitchell ryanmitchell deleted the feature/custom-static-caching-url-store-path branch January 29, 2024 19:16
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.

Static Cache not invalidating correctly
2 participants