1

Our old .Net framework APIs utilized the Strathweb.CacheOutput.WebApi2 which took care of server-side caching and set the appropriate client side headers in order to implement a form of output caching.

In that scheme, during project startup the following was injected to create a cache key. There is more custom code for our implementation that is appended to the key but this is enough to start the conversation. This method used the RedisOutputCache.

public class CacheKeyWithHeadersGenerator : DefaultCacheKeyGenerator
{
    public override string MakeCacheKey(HttpActionContext context, MediaTypeHeaderValue mediaType,
        bool excludeQueryString = false)
    {
        const string itemSeparator = "-";
        const string paramSeparator = "=";

        var cacheKey = base.MakeCacheKey(context, mediaType, excludeQueryString);
        var requestHeader = context.Request.GetHeaders();

        cacheKey += $"{itemSeparator}isdr{paramSeparator}{requestHeader.IsDR}";

Similar functionality is needed as we migrate to .Net 5, but I would like to know my options as there does not appear to be much in that covers this. In order for this to work, the rule that the presence of an Authorization header must be overridden.

Can anyone point me in the right direction? Should I be using Distributed Caching instead?

Edit 1

This question may be a bit hard to understand. I am attempting to cache at the client side using a custom cache key to contain the userid and other information contained in the Authorization header (as Strathweb did) in .Net 5 web api. In other words, data would be both client cached and server cached by utilizing a custom cache key in addition to what is sent via the query.

Lee Z
  • 802
  • 2
  • 13
  • 39

0 Answers0