Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Cache] Use correct expiry in ChainAdapter#38635

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:4.4fromNyholm:issue-38632-cache-chain
Oct 21, 2020

Conversation

@Nyholm
Copy link
Member

@NyholmNyholm commentedOct 19, 2020
edited
Loading

QA
Branch?4.4
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#38632
LicenseMIT
Doc PRn/a

When we are syncing the chain, Let's use expiry if we have it. If not, fallback to defaultLifetime.

TODO:

  • Add tests

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks, this looks good to me. Now waiting for a test case :)

@Nyholm
Copy link
MemberAuthor

I added a test. I needed to use an adapter that extends AbstractAdapter.

@nicolas-grekas
Copy link
Member

Thank you@Nyholm.

@nicolas-grekasnicolas-grekas merged commit5a4be68 intosymfony:4.4Oct 21, 2020
@Nyholm
Copy link
MemberAuthor

Thank you for merging.

@NyholmNyholm deleted the issue-38632-cache-chain branchOctober 21, 2020 09:38
@NyholmNyholm mentioned this pull requestOct 24, 2020
fabpot added a commit that referenced this pull requestOct 25, 2020
This PR was merged into the 4.4 branch.Discussion----------[Cache] Fixed broken test| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       || License       | MIT| Doc PR        |I added this line of code in#38635However, some time between 4.4 and 5.x the `FilesystemAdapterTest::rmdir()` was removed. This PR make sure tests does not fail on 5.x.I target 4.4, I believe it will be simple to merge up to 5.1 and 5.x. Let me know if I should target 5.x instead.Commits-------e17797c [Cache] Fixed broken test
This was referencedOct 28, 2020

if (0 <$defaultLifetime) {
if (isset($item->metadata[CacheItem::METADATA_EXPIRY])) {
$item->expiresAt(\DateTime::createFromFormat('U.u',$item->metadata[CacheItem::METADATA_EXPIRY]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just update to latest release with this change and it broke my site. As i know the expiry value is always a float number without precision (microsecond part). UsesU.u causing problem here. The format should beU. Can you advice?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you elaborate whyU.u casing a problem?

It seams to work:https://3v4l.org/pdadj

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

please open an issue with the error message you see and a reproducer or a failing test case ideally

Nyholm reacted with thumbs up emoji

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I suppose we should usesprintf('%.3F', ...)
the issue happens when the expiry is an int

phamviet reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, in my case expiry was int, not float.

simple.cache:        default_lifetime: 86400        adapters:          - cache.adapter.apcu          - cache.adapter.redis
public function isPartner(User $user): bool    {        return $this->simpleCache->get(md5((string)$user->getId() . __METHOD__), function (ItemInterface $item) use ($user) {            $item->expiresAfter(86400 * 7); // 1 week            $item->tag(md5((string)$user->getId()));                       // compute            return false;        });    }

Copy link
Member

@nicolas-grekasnicolas-grekasOct 28, 2020
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

thanks,@phamviet would you mind sending a PR with the fix and a test case, please?
for branch 4.4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It is middle-night my time and I would do it tomorrow if it is convenient.

nicolas-grekas and derrabus reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It is hard to me to reproduce myself today and finally i found down the problem could happen with ArrayAdapter in a race condition making expiry to be int. I'm not sure how could it happen like that. BTW, the PR is at#38879.

nicolas-grekas added a commit that referenced this pull requestOct 29, 2020
…ace conditions (phamviet)This PR was merged into the 4.4 branch.Discussion----------[Cache] Fixed expiry could be int in ChainAdapter due to race conditions| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |Fix#38635| License       | MIT| Doc PR        | noThis bug is hard to re-produce and seems only happen with ArrayAdapter only.Steps to reproduce:cache.yaml```simple.cache:        adapters:          - cache.adapter.array          - cache.adapter.redis``````phpif (isset($item->metadata[CacheItem::METADATA_EXPIRY])) {    $logger->debug($item->key, $item->metadata);    $format = is_int($item->metadata[CacheItem::METADATA_EXPIRY]) ? 'U' : 'U.u';    $item->expiresAt(\DateTime::createFromFormat($format, $item->metadata[CacheItem::METADATA_EXPIRY])); }```Refresh webpage multiple time to make web server busy and logs:```[2020-10-29T17:04:51.119653+07:00] application.DEBUG: item-key {"expiry":1603965892.118222,"ctime":4} [][2020-10-29T17:04:54.322937+07:00] application.DEBUG: item-key {"expiry":1603965895.308393,"ctime":17} [][2020-10-29T17:04:54.745923+07:00] application.DEBUG: item-key {"expiry":1603965895,"ctime":16} []```Commits-------268816f [Cache] Fixed expiry maybe int due too race conditions
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@phamvietphamvietphamviet left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

5 participants

@Nyholm@nicolas-grekas@phamviet@derrabus@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp