hassanhabib/RESTFulSense

FOUNDATIONS: Add Built-In Caching for Existing Calls within Interval

hassanhabib opened this issue · 1 comments

Proposal:

We need to consider adding an option to supporting In-Memory or Redis caching integration out of the box with RESTfulSense.

Here's a scenario:
Consider a system that makes several calls to the same API with the same parameters in less than 1 second. And optimization effort here can be done to offload some of the latency cost on the API consumer side.

Here's how I visualize this to look like:

Specific Operation Configuration

        private async ValueTask<T> GetAsync<T>(string relativeUrl) =>
            await this.apiClient.GetContentAsync<T>(relativeUrl, enableCaching: true, cacheInvalidation: 1000);

Global Configuration

        private readonly IRESTFulApiFactoryClient apiClient;

        public ApiBroker(IRESTFulApiFactoryClient apiClient)
        {    
            this.apiClient = apiClient;
            this.apiClient.ConfigureCache(enableCaching: true, cacheInvalidation: 1000);
        }

External Source Configuration

Contract

public interface IRESTFulSenseCaching
{
    ValueTask<T> TryGetCachedValue(string key);
}

Utilization

        public ApiBroker(IRESTFulApiFactoryClient apiClient, IRESTFulSenseCache externalCacheSource)
        {    
            this.apiClient = apiClient;
            this.apiClient.ConfigureCache(enableCaching: true, cacheInvalidation: 1000, source: externalCacheSource);
        }

I discussed this with @BrianLParker and Christo - still researching whether it's needed or not.