Table of Contents

Class UpdatingCachedReferencedResource

Namespace
Acuit.Pinpoint.ResourceManagement
Assembly
Acuit.Pinpoint.ResourceManagement.Abstractions.dll

A base class for resources referenced by resource providers derived from ResourceProvider that updates the resource value upon "update-needed" signals and caches resource values locally.

public abstract class UpdatingCachedReferencedResource : UpdatingReferencedResource, IDisposable
Inheritance
UpdatingCachedReferencedResource
Implements
Inherited Members

Remarks

This works the same as UpdatingReferencedResource, with the addition of caching. Implementations should follow the same rules as for UpdatingReferencedResource, with the following changes:

  1. If a value for the resource exists in the cache, it will be used as the initial resource value. When this happens, GetUpdatedResourceValueAsync(CancellationToken) will not be called initially; it will be called for the first time when the change token from GetUpdateNeededToken() is signaled.
  2. Implementations can optionally override OnInitializedFromCache(CachedEntry) to detect when the initial resource value is retrieved from the cache, using the CachedEntry parameter to determine when the next update will be required. (GetUpdateNeededToken() will be called directly after OnInitializedFromCache(CachedEntry) gets called.)

Constructors

UpdatingCachedReferencedResource(Uri, IErrorHandler, ILocalResourceCache, ITimeService)

Initializes a new instance of the UpdatingCachedReferencedResource class.

protected UpdatingCachedReferencedResource(Uri url, IErrorHandler errorHandler, ILocalResourceCache localResourceCache, ITimeService timeService)

Parameters

url Uri

The resource URL.

errorHandler IErrorHandler

The error handler service.

localResourceCache ILocalResourceCache

The local resource cache.

timeService ITimeService

The time service.

Exceptions

ArgumentNullException

url is null.

ArgumentNullException

errorHandler is null.

ArgumentNullException

localResourceCache is null.

ArgumentNullException

timeService is null.

Methods

Dispose(bool)

Closes and releases all resources used by the ReferencedResource.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true when this is in response to a call to Dispose().

Remarks

Derived classes should override this when they have any resources that should be disposed.

GetResourceValue(CancellationToken)

Gets the resource value. Derived classes can override the default behavior, which simply calls GetUpdatedResourceValueAsync(CancellationToken).

protected override Task<object> GetResourceValue(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token that can be used to request canceling getting the updated resource value.

Returns

Task<object>

A task that represents the asynchronous operation. The value of its Result property contains the resource value.

Exceptions

Exception

The updated resource value could not be obtained. The implementation should throw a specific exception appropriate for the error. This can be thrown synchronously, or it can occur asynchronously, wrapped in an AggregateException as the faulted task's Exception.

OnInitializedFromCache(CachedEntry)

Gets called if and when the initial resource value was successfully retrieved from the local cache.

protected virtual void OnInitializedFromCache(CachedEntry cachedEntry)

Parameters

cachedEntry CachedEntry

The entry retrieved from the local cache.

Remarks

Derived classes can override this to use this information to determine when the next resource value update should occur (e.g., based on the timestamp of the cache entry).

The base implementation does nothing and need not be called.