Improve cache when fetching lessons #108
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Due to the way how currently our code works fetching lessons from API is done on every
init
(I get it even on front end, not just in Dashboard).If request is successful the response is cached, but if it is not our server will be hammered. To prevent that I cached empty array with 5 minutes lifetime in case that request fails.
Another problem is that
$url
can be filtered, but the cache key is never changed - meaning that even if $url is changed user will keep getting lessons which were fetched from old$url
until the cache expires (which can be up to a week).I used
$url
in order to make$cache_key
unique and left it unchanged in order to make possible (future) debugging easier.Quality assurance