0

There are cache tag attributes like

  • vary-by-query
  • vary-by-route
  • vary-by-cookie
  • vary-by-user
  • vary-by priority

can be used in CSHTML directly for MVC.

What can be the best implementation to achieve the same in ASP.netCore for a cache mechanism implemented using IDistributedCache ?

Craig H
  • 2,001
  • 1
  • 14
  • 18
sntpcvan
  • 5
  • 1
  • 2

1 Answers1

0

There's no concept of vary in IDistributedCache. The cache tag attributes/response caching in general, is implemented as part of the request pipeline. While you can utilize IDistributedCache within the request pipeline, it is not part of that pipeline and doesn't natively have access to anything from the request.

You can somewhat implement this via the key of the entry you're adding. For example, if you want to vary the cache on the logged in user, simply prefix all your keys with something like $"User{userId}". Because the literal key would then be different user to user, the cache will obviously be as well. However, this is all a manual affair. You'd need to decide how to structure the keys and actually implement that in your app code when utilizing the cache.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444