Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Scenario : I have an object (result set from DB) stored in memory cache (cache.Add(key, object)). This cache is having absolute expiration as cache policy. Some times I need to clear the object in cache (cache.Remove(key)) before the expiration. My application is running on IIS which should never be stopped.

Question: So my question is how can I achieve this using a separate application ? Or is there any other way to clear cache before it reaches the absolute expiration ?
Posted
Comments
Krunal Rohit 3-Nov-15 4:50am    
You can't clear a browser's history via code because of browsers security reasons.

-KR
Howard Richards 3-Nov-15 5:36am    
He means the cache on the server not the client I believe
Member 11138484 3-Nov-15 5:43am    
I am not talking about browser's cache. I am talking about my application cache.

1 solution

As you're using ASP.NET you probably need to create a button and/or page that will do this, and this will trigger the code on your ASP.NET server to call cache.Remove(key).

Assuming clearing the cache is something you don't want normal users to do, the best approach is to put the page/button somewhere they cannot access it, or hide from normal users.

If you're using webforms, perhaps create a button on your page that when clicked performs the cache.Remove call, and set visibility to true only if it's you logged in.

If using MVC, perhaps a link that calls a method on the controller which calls cache.Remove
 
Share this answer
 
Comments
Member 11138484 3-Nov-15 5:47am    
Thanks for your reply Richards!

But I am invoking a WCF service which puts the objects in cache. So in such a scenario how can I achieve removing the items from cache ?
Howard Richards 3-Nov-15 5:48am    
You didn't mention that. So create a WCF method that clears the cache and create a button/page/link that calls this method.

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