Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Let's say i have this controller

public class abController : BaseApiController
{
        [HttpGet]
        [Route("api/x", Name = "x1")]
        [CacheOutput(ServerTimeSpan = 3600, ClientTimeSpan = 3600)]
        public async Task<IHttpActionResult> getX([FromUri] xRequest request)
        {

        }


        [HttpGet]
        [Route("api/y", Name = "y")]
        [ActionName("y")]
        [CacheOutput(ServerTimeSpan = 3600, ClientTimeSpan = 3600)]
        public async Task<IHttpActionResult> getY([FromUri] yRequest request)
        {

        }
}


as u can see there is caching on both methods, but for method
getY
there is another controller who does POST so when POST is done i want the caching on method getY to be skipped



    public class addController: BaseApiController
{
        [HttpPost]
        [InvalidateCacheOutput("y")]
        [Route("api/y/add", Name = "add")]
        public async Task<IHttpActionResult> addY([FromUri] addYRequest request)
        {

        }
}


What I have tried:

As u can see i put action Name on the method that i want to skip the caching in it
[ActionName("y")]


and now in method addY i put
[InvalidateCacheOutput("y")]
but it's not working

i want when addY is called the caching on method getY to be skipped
Posted
Updated 8-Jun-20 2:43am

1 solution

It looks like you're using the Strathweb.CacheOutput library. Looking at the documentation, the value passed to InvalidateCacheOutput needs to be the method name whose cache you want to invalidate. You don't have a method called y on the addController, so the attribute does nothing.

Try:
C#
[HttpPost]
[InvalidateCacheOutput(nameof(abController.getY), typeof(abController))]
[Route("api/y/add", Name = "add")]
public async Task<IHttpActionResult> addY([FromUri] addYRequest request) ...
GitHub - filipw/Strathweb.CacheOutput: ASP.NET Web API CacheOutput - library to allow you to cache the output of ApiControllers[^]
 
Share this answer
 
Comments
Member 14800672 9-Jun-20 17:41pm    
Thanks.. It is working now.. But can i do it based on the query string of the url. I mean if i have id parameter in the url.. Then when i click addY for id=1 i want to invalidate the cache for getY with parameter id=1 not other ids
Richard Deeming 10-Jun-20 5:00am    
There doesn't seem to be a way to do that. There's an open ticket from last November asking how to do it, with no replies.

Invalidate cache for certain query strings · Issue #258 · filipw/Strathweb.CacheOutput · GitHub[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900