Class SecureCache
Provides a secure cache implementation.
[Export(typeof(ISecureCache))]
[Shared]
public class SecureCache : ISecureCache, ICache, IDisposable
- Inheritance
-
SecureCache
- Implements
- Inherited Members
Remarks
The values are kept in memory, in the browser session of the application. The expiration arguments (timeout and isSlided) are ignored,
and a value added under a key that already exists does not replace the existing one.
Methods
Dispose()
Disposes the cache object. There is nothing to release.
public void Dispose()
GetAsync<TValue>(string, CancellationToken)
Asynchronously gets the value associated with the specified key.
public Task<TValue?> GetAsync<TValue>(string key, CancellationToken cancellation = default)
Parameters
keystringThe key of the value to get.
cancellationCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- Task<TValue>
A task that represents the asynchronous operation. The task result contains the value associated with the specified key.
Type Parameters
TValue
Exceptions
- KeyNotFoundException
There is no value for the key.
Get<TValue>(string)
Gets the value associated with the specified key.
public TValue Get<TValue>(string key)
Parameters
keystringThe key of the value to get.
Returns
- TValue
The value associated with the specified key.
Type Parameters
TValue
Exceptions
- KeyNotFoundException
There is no value for the key.
Initialize(string)
Empties the cache. The store name is not used.
public void Initialize(string store)
Parameters
storestringThe store name, which is ignored.
PutAsync<T>(string, TimeSpan, T, bool, CancellationToken)
Asynchronously adds the specified key and value to the cache. The expiration arguments are ignored and nothing is done when the key already exists.
public Task PutAsync<T>(string key, TimeSpan timeout, T value, bool isSlided = false, CancellationToken cancellation = default)
Parameters
keystringThe key of the element to add.
timeoutTimeSpanThe expiration time, which is ignored.
valueTThe value of the element to add.
isSlidedboolThe sliding expiration flag, which is ignored.
cancellationCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.
Type Parameters
T
PutAsync<T>(string, T, CancellationToken)
Asynchronously adds the specified key and value to the cache. Nothing is done when the key already exists.
public Task PutAsync<T>(string key, T value, CancellationToken cancellation = default)
Parameters
keystringThe key of the element to add.
valueTThe value of the element to add.
cancellationCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- Task
A task that represents the asynchronous operation.
Type Parameters
T
Put<T>(string, TimeSpan, T, bool)
Adds the specified key and value to the cache. The expiration arguments are ignored and nothing is done when the key already exists.
public void Put<T>(string key, TimeSpan timeout, T value, bool isSlided = false)
Parameters
keystringThe key of the element to add.
timeoutTimeSpanThe expiration time, which is ignored.
valueTThe value of the element to add.
isSlidedboolThe sliding expiration flag, which is ignored.
Type Parameters
T
Put<T>(string, T)
Adds the specified key and value to the cache. Nothing is done when the key already exists.
public void Put<T>(string key, T value)
Parameters
keystringThe key of the element to add.
valueTThe value of the element to add.
Type Parameters
T
Remove(string)
Removes the value with the specified key from the cache.
public bool Remove(string key)
Parameters
keystringThe key of the element to remove.
Returns
- bool
True if the element is successfully found and removed; otherwise, false.
RemoveAsync(string, CancellationToken)
Asynchronously removes the value with the specified key from the cache.
public Task<bool> RemoveAsync(string key, CancellationToken cancellation = default)
Parameters
keystringThe key of the element to remove.
cancellationCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- Task<bool>
A task that represents the asynchronous operation. The task result contains a boolean indicating whether the element was successfully found and removed.
TryGetValueAsync<TValue>(string, CancellationToken)
Asynchronously tries to get the value associated with the specified key.
public Task<TValue?> TryGetValueAsync<TValue>(string key, CancellationToken cancellation = default)
Parameters
keystringThe key of the value to get.
cancellationCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- Task<TValue>
A task that represents the asynchronous operation. The task result contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.
Type Parameters
TValue
TryGetValue<TValue>(string, out TValue?)
Tries to get the value associated with the specified key.
public bool TryGetValue<TValue>(string key, out TValue? value)
Parameters
keystringThe key of the value to get.
valueTValueWhen this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.
Returns
- bool
True if the cache contains an element with the specified key; otherwise, false.
Type Parameters
TValue