Class HttpContextRequestAppCache
Implements a IAppCache on top of Microsoft.AspNetCore.Http.IHttpContextAccessor
Namespace: Umbraco.Cms.Core.Cache
Assembly: Umbraco.Web.Common.dll
Syntax
public class HttpContextRequestAppCache : FastDictionaryAppCacheBase, IRequestCache, IAppCache
Remarks
The HttpContext is not thread safe and no part of it is which means we need to include our own thread safety mechanisms. This relies on notifications: UmbracoRequestBeginNotification and UmbracoRequestEndNotification in order to facilitate the correct locking and releasing allocations.
Constructors
View SourceHttpContextRequestAppCache(IHttpContextAccessor)
Initializes a new instance of the HttpContextRequestAppCache class with a context, for unit tests!
Declaration
public HttpContextRequestAppCache(IHttpContextAccessor httpContextAccessor)
Parameters
| Type | Name | Description |
|---|---|---|
| IHttpContextAccessor | httpContextAccessor |
Properties
View SourceIsAvailable
Gets a value indicating whether the request cache is available.
Declaration
public bool IsAvailable { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
View SourceEnterReadLock()
Enters a read lock on the underlying cache.
Declaration
protected override void EnterReadLock()
EnterWriteLock()
Enters a write lock on the underlying cache.
Declaration
protected override void EnterWriteLock()
ExitReadLock()
Exits the read lock on the underlying cache.
Declaration
protected override void ExitReadLock()
ExitWriteLock()
Exits the write lock on the underlying cache.
Declaration
protected override void ExitWriteLock()
Get(string, Func<object?>)
Gets or creates an item identified by its key.
Declaration
public override object? Get(string key, Func<object?> factory)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key of the item. |
| Func<object> | factory | A factory function that can create the item. |
Returns
| Type | Description |
|---|---|
| object | The item. |
Remarks
Null values returned from the factory function are never cached.
GetDictionaryEntries()
Gets all dictionary entries from the underlying cache.
Declaration
protected override IEnumerable<KeyValuePair<object, object>> GetDictionaryEntries()
Returns
| Type | Description |
|---|---|
| IEnumerable<KeyValuePair<object, object>> | The dictionary entries. |
Remarks
Must be called from within the appropriate locks.
GetEntry(string)
Gets an entry from the underlying cache.
Declaration
protected override object? GetEntry(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The full prefixed cache key. |
Returns
| Type | Description |
|---|---|
| object | The cached value, or |
Remarks
Must be called from within the appropriate locks.
GetEnumerator()
Declaration
public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<KeyValuePair<string, object>> |
Remove(string)
Removes a value from the request cache.
Declaration
public bool Remove(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key of the item to remove. |
Returns
| Type | Description |
|---|---|
| bool |
|
RemoveEntry(string)
Removes an entry from the underlying cache.
Declaration
protected override void RemoveEntry(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The full prefixed cache key. |
Remarks
Must be called from within the appropriate locks.
Set(string, object?)
Sets a value in the request cache.
Declaration
public bool Set(string key, object? value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key of the item to set. |
| object | value | The value to store in the cache. |
Returns
| Type | Description |
|---|---|
| bool |
|