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

[5.x] Use existing getUrlsCacheKey method instead of duplicating the creation logic #10836

Merged
merged 3 commits into from
Sep 25, 2024

Conversation

dadaxr
Copy link
Contributor

@dadaxr dadaxr commented Sep 25, 2024

While overriding the ApplicationCacher with my own Cacher, to change the logic behind cache key creation, I found I had to override 2 methods instead of one because the logic was duplicated...

There is no breaking change in here, just using an already existing method instead.

the getUrls where recreating manually the cache key wherease there already is a method to do that ...
@duncanmcclean duncanmcclean changed the title use existing getUrlsCacheKey method instead of duplicating the creation logic [5.x] Use existing getUrlsCacheKey method instead of duplicating the creation logic Sep 25, 2024
@duncanmcclean
Copy link
Member

While overriding the ApplicationCacher with my own Cacher, to change the logic behind cache key creation, I found I had to override 2 methods instead of one because the logic was duplicated...

Out of curiosity, what are you changing in your custom cacher?

@dadaxr
Copy link
Contributor Author

dadaxr commented Sep 25, 2024

I have a website where I can't use the default application cache (half strategy) out of the box because there are many parts of my templates which would need {{nocache}} tag... (I tried and 400 go of storage were filled within a day because of how the nocache tag works ...)

To be short it's a website where a user can choose a shop and many parts of the website depends of this selection, moreover there is also a notion of "current marketing operation" (with a period of validty) which also modify many parts of the website... so many more {{ nocache tags }} At the end even with the half strategy enabled, the website was slow because the number of nocache tags to process (without speaking of the storage problem)

So I decided to try to "alter" the way the default application cache works... by not caching a page by it's url but by it's url + some other context param (like the selected shop or the current marketing operation) ... So I dont have to use many nocache tag because ... I can just cache the different variation of the same url... and to do that I appears I just have to override the "makeHash" function which is responsible to generate the cachekey

The whole procedure (and even the feasibility) was not documented but it appears it's quite simple because the AbstractCacher (from which the ApplicationCacher inherits) is already built to be extendable (with custom driver).

@jasonvarga jasonvarga merged commit 465652b into statamic:5.x Sep 25, 2024
16 checks passed
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.

3 participants