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
I have a cached data that takes 5 minutes to execute the closure, this process of recalculating the cache is executed on demand only in certain circumstances, validating the administrator's permissions and with a special parameter in the URL request. In addition this cache has a TTL of 24 hours
The first approach (which was incorrect), when I needed to recalculate the cache, first I would do a
forget
and then I would do aremember
. However, if at the time the value was being calculated (after theforget
but during the 5 minutes it takes to process) a request arrives, theget
(orremember
) that the user does would give null because the value had already been deleted from the cache and had not yet been saved again.Obviously the admin should execute the
put
method to overwrite the value from the cache, if while the recalculation process is running, a request arrives, the value that is still in the cache and was not overwritten is used.I've looked at the documentation for
flexible
but it's not exactly what I need, because the cache might still be valid when it needs to be recalculated.I am aware that this can be solved by putting the closure in a separate method and differentiating the user calls vs. the administrator calls.
But the proposal is to use a new method to make it clearer and save a few lines of code.
Another alternative would be to add the parameter
$when
to theremember
function, but I thought a new method would be better.