-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Use the default expiry when saving (not when creating) items #37562
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
Conversation
@@ -90,8 +89,7 @@ static function ($deferred) { | |||
$this->invalidateTags = \Closure::bind( | |||
static function (AdapterInterface $tagsAdapter, array $tags) { | |||
foreach ($tags as $v) { | |||
$v->defaultLifetime = 0; | |||
$v->expiry = null; | |||
$v->expiry = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does "0" mean "infinity"? then there is a small glitch if one sets 0
as the timestamp for expiry, which will be confused with "infinity".
Should/can we use "-1" for this instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, according to \Symfony\Component\Cache\Traits\AbstractTrait::doSave() "0" means "infinity". Also, $defaultLifetime = 0 in adapter's constructors mean the same.
From a user point of view there are only ways to specify expiration:
- $defaultLifetime in adapter. And there 0 is already mean "infinity"
- CacheItemInterface::expiresAfter(). There 0 means number of seconds, so I guess it shouldn't confuse user.
- CacheItemInterface::expiresAt(). Its impossible to pass 0 here.
BTW, this is only place where $item->expiry is set to "0" explicitly, because we want to ignore adapter's default lifetime here if any is set when store tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CacheItemInterface::expiresAt(). Its impossible to pass 0 here.
got it: the unix epoch time here is 0.0
, not 0
.
@@ -90,8 +89,7 @@ static function ($deferred) { | |||
$this->invalidateTags = \Closure::bind( | |||
static function (AdapterInterface $tagsAdapter, array $tags) { | |||
foreach ($tags as $v) { | |||
$v->defaultLifetime = 0; | |||
$v->expiry = null; | |||
$v->expiry = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CacheItemInterface::expiresAt(). Its impossible to pass 0 here.
got it: the unix epoch time here is 0.0
, not 0
.
Thank you @philipp-kolesnikov. |
54c709c
to
49e9f32
Compare
If you have some time before I do, I merged this in branch 5.1 but forgot some things apparently since tests fail: |
This patch will fix failed tests:
|
@philipp-kolesnikov thanks again, fixed. |
@philipp-kolesnikov unfortunately this breaks invalidating items by tags for me. See #37667 The cause is this change: 49e9f32#diff-2fe2f12a84197b6987fbd5e133cd09aeR92 Do you have an idea whats happening or how to fix it? 😊 Thanks in advance. |
@dmaicher sorry for this regression.
I'll make a PR with test case from #37667 included. |
This PR is for align expiration handling in ChainAdapter with ChainCache as proposed in #37263.