Skip to content

[Lock] Expose an expiringDate and isExpired method in Lock #22543

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

Closed
wants to merge 2 commits into from

Conversation

jderusse
Copy link
Member

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #22452
License MIT
Doc PR NA

This PR store the expiration date of the lock in the key and exposes public method to let the user know the state of the Lock expiration.

@jderusse jderusse changed the title Expose an expiringDate and isExpired method in Lock [Lock] Expose an expiringDate and isExpired method in Lock Apr 26, 2017
@jderusse jderusse force-pushed the lock-expose-expiration branch 2 times, most recently from 09c696f to 5990f0a Compare April 26, 2017 22:31
*/
public function reduceExpiringDate(\DateTimeImmutable $expiringDate)
{
if (null === $this->expiringDate || $this->expiringDate > $expiringDate) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not throw an exception when $this->expiringDate <= $expiringDate?

Copy link
Member Author

@jderusse jderusse May 31, 2017

Choose a reason for hiding this comment

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

I would do that in a method named setExpiringDate. But I didn't want to backport such logic in this class. It purpose it to move foward the expiration date regardless the previous value.

Copy link
Member

Choose a reason for hiding this comment

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

The method name is not clear to me. reduce means that it's going to expire earlier than before, right. But you say that the purpose is to "move forward".

Copy link
Member Author

Choose a reason for hiding this comment

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

When several store are combined, they can define different expiration date, the goal is to take the shorter one. cf if (.. && $this->expiringDate > $expiringDate) { set value}

Indeed, reducing a date does not really make sens. What's about reduceLifeLength or advanceExpiringDate?

Copy link
Member

Choose a reason for hiding this comment

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

It's common to use lifetime or ttl when talking about storage (session, cache, authorizations, ...). Could we use the same wording here? (reduceLifetime could do the job then)

Copy link
Member Author

Choose a reason for hiding this comment

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

Finally replaced reduceExpiringDate(\Datetime $newExpiringDate) by reduceLifetime(float $ttl)

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Apr 27, 2017
@nicolas-grekas nicolas-grekas changed the base branch from master to 3.4 May 23, 2017 16:48
@jderusse jderusse force-pushed the lock-expose-expiration branch 2 times, most recently from d318ee4 to d5ae790 Compare July 31, 2017 06:48
@jderusse jderusse force-pushed the lock-expose-expiration branch from d5ae790 to 7d69adc Compare July 31, 2017 06:58
@chalasr chalasr added the Lock label Jul 31, 2017
@fabpot
Copy link
Member

fabpot commented Aug 23, 2017

What's the status of this PR? I'd like to merge/close all PRs about the lock component ASAP to avoid having to revert the component for 3.4.

@jderusse
Copy link
Member Author

@fabpot PR waiting for review/approval. As far as I know, nothing to add from my side.

@fabpot
Copy link
Member

fabpot commented Aug 29, 2017

Thank you @jderusse.

@fabpot fabpot closed this Aug 29, 2017
fabpot added a commit that referenced this pull request Aug 29, 2017
…Lock (jderusse)

This PR was squashed before being merged into the 3.4 branch (closes #22543).

Discussion
----------

[Lock] Expose an expiringDate and isExpired method in Lock

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22452
| License       | MIT
| Doc PR        | NA

This PR store the expiration date of the lock in the key and exposes public method to let the user know the state of the Lock expiration.

Commits
-------

2794308 [Lock] Expose an expiringDate and isExpired method in Lock
}

/**
* @return \DateTimeImmutable
Copy link
Member

Choose a reason for hiding this comment

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

\DateTimeImmutable|null

{
$newExpiringDate = \DateTimeImmutable::createFromFormat('U.u', (string) (microtime(true) + $ttl));

if (null === $this->expiringDate || $newExpiringDate < $this->expiringDate) {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if it really is expected behaviour that the method silently ignores any argument if it is no smaller than the existing expiration date.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO it's not an issue if a store ask for a TTL greater than the current one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants