pub struct LockManager { /* private fields */ }Expand description
Mints Locks against a cache.
Bind one in the container and resolve it; a lock taken through a different cache is a different lock.
Implementations§
Source§impl LockManager
impl LockManager
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Locks under a different prefix.
Worth changing when the cache is shared with something else that might pick the same names.
Sourcepub fn lock(&self, name: impl Into<String>, ttl: Duration) -> Lock
pub fn lock(&self, name: impl Into<String>, ttl: Duration) -> Lock
A lock called name, held for at most ttl.
Whether locks taken here are visible to other processes.
false for an in-process cache, which means on_one_server is not
doing what its name says. Worth asserting at boot rather than
discovering from a report that ran twice.
let locks = LockManager::new(Arc::new(MemoryCache::new()));
assert!(!locks.is_shared());Take this store’s word for it: locks here are visible to other processes.
For a Cache implemented outside this crate that has not overridden
Cache::is_shared — a Consul, an etcd, somebody’s own Redis client.
Nothing verifies the claim, so declaring it about a per-process store
disables the one check that would have caught it.
let locks = LockManager::new(Arc::new(MemoryCache::new())).declared_shared();
assert!(locks.is_shared());