Struct RandomAccessCache<TKey, TValue>.ReadWriteSession
Represents a session that can be used to read, modify or promote the cache record value.
Inherited Members
Namespace: DotNext.Runtime.Caching
Assembly: DotNext.Threading.dll
Syntax
public readonly struct RandomAccessCache<TKey, TValue>.ReadWriteSession : IDisposable, IAsyncDisposable
Remarks
While session alive, the record cannot be evicted.
Properties
| Edit this page View SourceValueRefOrNullRef
Gets a reference to a value.
Declaration
public ref readonly TValue ValueRefOrNullRef { get; }
Property Value
Type | Description |
---|---|
TValue | A reference to a value; or |
Methods
| Edit this page View SourceDispose()
Closes the session.
Declaration
public void Dispose()
Remarks
This method should be called only once. The method doesn't wait for the cache entry promotion.
DisposeAsync()
Closes the session.
Declaration
public ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous state of the cache entry promotion. |
Remarks
This method should be called only once. It's recommended to use this method to ensure that the cache entry is promoted. This is useful when the cache is rate-limited. Otherwise, use Dispose(), because concurrent promotions are handled by the single thread running in the background. Thus, awaiting of the returned task can cause contention over multiple writers.
SetValue(TValue)
Promotes or modifies the cache record value.
Declaration
public void SetValue(TValue value)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | The value to promote or replace the existing value. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The session is invalid; the value promotes more than once. |
TryGetValue(out TValue)
Tries to get the value of the cache record.
Declaration
public bool TryGetValue(out TValue result)
Parameters
Type | Name | Description |
---|---|---|
TValue | result | The value of the cache record. |
Returns
Type | Description |
---|---|
bool |