ResponseCache
is somewhat a replacement for OutputCache
; however, I would like to do server side caching as well as per parameter input.
According to some answers here and here, I should be using IMemoryCache
or IDistributedCache
to do this. I'm particularly interested in caching on controllers where the parameter is different, previously done in asp.net 4 with OutputCache
and VaryByParam
like so:
[OutputCache(CacheProfile = "Medium", VaryByParam = "id", Location = OutputCacheLocation.Server)]
public ActionResult Index(long id)
{
///...
}
How would I go about replicating this in asp.net core?
I encountered the same issue, none of the followings produce the expected cached-by-unique-parameters-values. Always returns the initial result:
VaryByQueryKeys = new[] { "*" }
VaryByQueryKeys = new[] { "searchparam" }
given
public async Task<IActionResult> Search([FromQuery] string searchparam)
Solution is prefix it with a
$
, that isVaryByQueryKeys = new[] { "$searchparam" }