CacheLock class abstract

An atomic lock. Only one owner can hold it at a time.

CacheLock lock = cache.lock('report', Duration(seconds: 10));
if (await lock.get()) {
  try { ... } finally { await lock.release(); }
}

Constructors

CacheLock(String name, Duration? ttl, [String? owner])

Properties

hashCode → int
The hash code for this object.
no setterinherited
name → String
Lock name.
final
owner → String
Random token of this owner. Pass it to lock() in another process to release the same lock there.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
ttl → Duration?
Lock is freed after this time even if not released. Null means never.
final

Methods

block(Duration timeout) → Future<bool>
Try to take the lock until timeout passes. True when taken.
get() → Future<bool>
Try to take the lock once. True when taken.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
release() → Future<bool>
Free the lock if this owner holds it. True when freed.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

randomOwner() → String
A random hex token.