/// <summary> /// Returning the most optimized result based on the MimeType and CompressionType from the IRequest. /// <param name="expireCacheIn">How long to cache for, null is no expiration</param> /// </summary> public static async Task <object> ToOptimizedResultUsingCacheAsync <T>( this IRequest req, ICacheClientAsync cacheClient, string cacheKey, TimeSpan?expireCacheIn, Func <T> factoryFn, CancellationToken token = default) { var cacheResult = await cacheClient.ResolveFromCacheAsync(cacheKey, req, token).ConfigAwait(); if (cacheResult != null) { return(cacheResult); } cacheResult = await cacheClient.CacheAsync(cacheKey, factoryFn(), req, expireCacheIn, token).ConfigAwait(); return(cacheResult); }