Class LockingMechanism
Mechanism for handling read and write locks
Inheritance
Namespace: Umbraco.Cms.Core.Scoping
Assembly: Umbraco.Core.dll
Syntax
public class LockingMechanism : ILockingMechanism
Constructors
View SourceLockingMechanism(IDistributedLockingMechanismFactory, ILogger<LockingMechanism>)
Constructs an instance of LockingMechanism
Declaration
public LockingMechanism(IDistributedLockingMechanismFactory distributedLockingMechanismFactory, ILogger<LockingMechanism> logger)
Parameters
Type | Name | Description |
---|---|---|
IDistributedLockingMechanismFactory | distributedLockingMechanismFactory | |
ILogger<LockingMechanism> | logger |
Methods
View SourceClearLocks(Guid)
Clears all lock counters for a given scope instance, signalling that the scope has been disposed.
Declaration
public void ClearLocks(Guid instanceId)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | Instance ID of the scope to clear. |
Dispose()
Declaration
public void Dispose()
EagerReadLock(Guid, Int32[])
Declaration
public void EagerReadLock(Guid instanceId, params int[] lockIds)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | |
System.Int32[] | lockIds |
EagerReadLock(Guid, Nullable<TimeSpan>, Int32[])
Eagerly acquires a read-lock
Declaration
public void EagerReadLock(Guid instanceId, TimeSpan? timeout = null, params int[] lockIds)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | |
System.Nullable<TimeSpan> | timeout | Timeout for the lock |
System.Int32[] | lockIds |
EagerWriteLock(Guid, Int32[])
Declaration
public void EagerWriteLock(Guid instanceId, params int[] lockIds)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | |
System.Int32[] | lockIds |
EagerWriteLock(Guid, Nullable<TimeSpan>, Int32[])
Eagerly acquires a write-lock
Declaration
public void EagerWriteLock(Guid instanceId, TimeSpan? timeout = null, params int[] lockIds)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | |
System.Nullable<TimeSpan> | timeout | Timeout for the lock |
System.Int32[] | lockIds |
EnsureLocks(Guid)
When we require a ReadLock or a WriteLock we don't immediately request these locks from the database, instead we only request them when necessary (lazily). To do this, we queue requests for read/write locks. This is so that if there's a request for either of these locks, but the service/repository returns an item from the cache, we don't end up making a DB call to make the read/write lock. This executes the queue of requested locks in order in an efficient way lazily whenever the database instance is resolved.
Declaration
public void EnsureLocks(Guid scopeInstanceId)
Parameters
Type | Name | Description |
---|---|---|
Guid | scopeInstanceId |
EnsureLocksCleared(Guid)
Declaration
public void EnsureLocksCleared(Guid instanceId)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId |
GetReadLocks()
Declaration
public Dictionary<Guid, Dictionary<int, int>>? GetReadLocks()
Returns
Type | Description |
---|---|
System.Nullable<Umbraco.Cms.Core.Dictionary<Guid, Umbraco.Cms.Core.Dictionary<System.Int32, System.Int32>>> |
GetWriteLocks()
Declaration
public Dictionary<Guid, Dictionary<int, int>>? GetWriteLocks()
Returns
Type | Description |
---|---|
System.Nullable<Umbraco.Cms.Core.Dictionary<Guid, Umbraco.Cms.Core.Dictionary<System.Int32, System.Int32>>> |
ReadLock(Guid, Int32[])
Declaration
public void ReadLock(Guid instanceId, params int[] lockIds)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | |
System.Int32[] | lockIds |
ReadLock(Guid, Nullable<TimeSpan>, Int32[])
Read-locks some lock objects lazily.
Declaration
public void ReadLock(Guid instanceId, TimeSpan? timeout = null, params int[] lockIds)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | Instance id of the scope who is requesting the lock |
System.Nullable<TimeSpan> | timeout | Timeout for the lock |
System.Int32[] | lockIds | Array of lock object identifiers. |
WriteLock(Guid, Int32[])
Declaration
public void WriteLock(Guid instanceId, params int[] lockIds)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | |
System.Int32[] | lockIds |
WriteLock(Guid, Nullable<TimeSpan>, Int32[])
Write-locks some lock objects lazily.
Declaration
public void WriteLock(Guid instanceId, TimeSpan? timeout = null, params int[] lockIds)
Parameters
Type | Name | Description |
---|---|---|
Guid | instanceId | Instance id of the scope who is requesting the lock |
System.Nullable<TimeSpan> | timeout | Timeout for the lock |
System.Int32[] | lockIds | Array of object identifiers. |