Class AcquiredLock
Represents an acquired lock.
Property Summary
-
$released protected
boolWhether the lock has already been released.
Method Summary
-
__construct() public
Constructor.
-
__destruct() public
Attempt to release the lock when it falls out of scope.
-
getAcquiredAt() public
Get the timestamp when the lock was acquired.
-
getRemainingTtl() public
Get remaining time until expiration in seconds.
-
getResource() public
Get the locked resource identifier.
-
getToken() public
Get the unique token identifying the lock owner.
-
getTtl() public
Get the time-to-live in seconds.
-
isExpired() public
Check if the lock has expired based on its TTL.
-
isReleased() public
Check whether the lock has already been released.
-
refresh() public
Refresh the lock with the engine that acquired it.
-
release() public
Release the lock with the engine that acquired it.
Method Detail
__construct() ¶ public
__construct(string $resource, string $token, int $ttl, float $acquiredAt, Cake\Lock\LockInterface|null $engine = null)
Constructor.
Parameters
-
string$resource The locked resource identifier.
-
string$token Unique token identifying the lock owner.
-
int$ttl Time-to-live in seconds.
-
float$acquiredAt Timestamp when the lock was acquired.
-
Cake\Lock\LockInterface|null$engine optional The engine that acquired the lock.
getAcquiredAt() ¶ public
getAcquiredAt(): float
Get the timestamp when the lock was acquired.
Returns
floatgetRemainingTtl() ¶ public
getRemainingTtl(): float
Get remaining time until expiration in seconds.
Returns
floatRemaining seconds, may be negative if expired.
getToken() ¶ public
getToken(): string
Get the unique token identifying the lock owner.
This token is used to verify ownership when releasing or refreshing the lock.
Returns
stringisExpired() ¶ public
isExpired(): bool
Check if the lock has expired based on its TTL.
Note: This is a local check based on the original TTL. The actual lock state in the backend may differ due to clock skew or manual intervention.
Returns
boolTrue if the lock has likely expired.
isReleased() ¶ public
isReleased(): bool
Check whether the lock has already been released.
Returns
boolrefresh() ¶ public
refresh(int|null $ttl = null): bool
Refresh the lock with the engine that acquired it.
Parameters
-
int|null$ttl optional New TTL in seconds. If null, uses the original TTL.
Returns
boolTrue if the lock was refreshed, false otherwise.
release() ¶ public
release(): bool
Release the lock with the engine that acquired it.
Returns
boolTrue if the lock was released, false otherwise.