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

[Laravel] Caching strategy and warm up #6735

Closed
toitzi opened this issue Oct 18, 2024 · 6 comments · Fixed by #6751
Closed

[Laravel] Caching strategy and warm up #6735

toitzi opened this issue Oct 18, 2024 · 6 comments · Fixed by #6751

Comments

@toitzi
Copy link
Contributor

toitzi commented Oct 18, 2024

Description
While running into performance issues on my machine with requests taking up to seconds, i noticed that API Platform decides between 2 cache methods (array/file) based on the APP_DEBUG setting which was quite confusing. I get that the default value for using laravels cache setting CACHE_STORE is file and that in development instances you wouldn't wanna cache at all. So i can also see why you would check for another .env setting (like DEBUG). However i couldn't find that in the documentation (maybe i missed it). So i'd like to propose the following changes:

  1. Document that the DEBUG setting changes the caching strategy for api platform (or switch to a config setting or to ENVIRONMENT (production/local) setting or whatever - altough i would prefer something like using the ENVIRONMENT setting, ultimately i think it does not really matter as long as it is in the docs)

  2. Reagardless of the Above, keep array in "debug" cases but use the CACHE_STORE setting which comes with laravel for production e.g non debug. It defaults to file anyway and allows more control with no overhead.

  3. Since that cache is stored "forever" when it is first accessed (Metadata etc.. does not change on production environments), it could be cool/useful to hook into the Optimze command of laravel (described here) and "warm up" the cache with that data. I think that would be pretty neat.

Let me know what you think about that, i will happily submit a PR :)

@toitzi
Copy link
Contributor Author

toitzi commented Oct 23, 2024

Nevermind, cache warm up seems to happen anyway when registering routes...using the laravel conf for cache provider would still be great, in case some might want to use memory caching like apcu instead of file caches

@soyuka
Copy link
Member

soyuka commented Oct 24, 2024

Indeed we didn't thought it'd need to be documented. In symfony we rely on the debug value as if you don't debug you probably want the metadata to be cached no? Maybe that we should just add a configuration for this and default to the debug value?

👍 to use the CACHE_STORE, I wasn't aware of this setting do you have a reference on how to use this?

@amermchaudhary
Copy link
Contributor

amermchaudhary commented Oct 24, 2024

@soyuka
Laravel Cache Documentation: https://laravel.com/docs/11.x/cache#main-content
Cache config file in a Laravel project : config/cache.php
Cache environment variables in Laravel: CACHE_STORE,CACHE_PREFIX

@amermchaudhary
Copy link
Contributor

In my PR above, I'm using Laravel's cache and also setting the default cache driver to null for workbench tests

toitzi added a commit to toitzi/core that referenced this issue Oct 25, 2024
Make use of the default laravel cache setting, makes it possible for developers to configure where data should be cached

Closes: api-platform#6735
Signed-off-by: Tobias Oitzinger <[email protected]>
toitzi added a commit to toitzi/core that referenced this issue Oct 25, 2024
Make use of the default laravel cache setting, makes it possible for developers to configure where data should be cached

Closes: api-platform#6735
Signed-off-by: Tobias Oitzinger <[email protected]>
toitzi added a commit to toitzi/core that referenced this issue Oct 25, 2024
Make use of the default laravel cache setting, makes it possible for developers to configure where data should be cached

Closes: api-platform#6735
Signed-off-by: Tobias Oitzinger <[email protected]>
@toitzi
Copy link
Contributor Author

toitzi commented Oct 25, 2024

@soyuka You are right my bad, debug is the recommended setting anyway for this (also in laravel). So it is fine leave that part as is.

Opend a PR for using laravel cache settings tho, since that is what one would probably expect.

soyuka pushed a commit to toitzi/core that referenced this issue Oct 25, 2024
Make use of the default laravel cache setting, makes it possible for developers to configure where data should be cached

Closes: api-platform#6735
Signed-off-by: Tobias Oitzinger <[email protected]>
soyuka pushed a commit that referenced this issue Oct 25, 2024
@toitzi
Copy link
Contributor Author

toitzi commented Oct 25, 2024

Closed with #6751

@toitzi toitzi closed this as completed Oct 25, 2024
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 a pull request may close this issue.

3 participants