...">

How to remove OutputCache programmatically for ascx?

I have a page1.aspx:

<%@ Register src="uc1.ascx" tagname="UcHead" tagprefix="uc1" %>

and uc1.ascx with OutputCache:

<%@ OutputCache Duration="18000" VaryByParam="*"  %> 

How can I click a button on another OutputCachepage2.aspx to delete for uc1.ascx or page1.aspx?

When OutputCache is in page1.aspx, I can use the following code to remove OutputCache:

string url = "/page1.aspx"; 
HttpResponse.RemoveOutputCacheItem(url); 

But this does not work when OutputCache is in uc1.ascx.

+3
source share
1 answer

Ok try this

On the download page of your user control, put:

HttpRuntime.Cache.Insert("myCacheKey", DateTime.Now);

BasePartialCachingControl pcc = Parent as BasePartialCachingControl;
pcc.Dependency = new CacheDependency(null, new string[]{"myCacheKey"});

Change the key to anything you want to control it.

Then in the code of the event you want to clear the cache:

Cache.Insert("myCacheKey", DateTime.Now);

http://dotnetslackers.com/ASP_NET/re-63091_ASP_NET_clear_user_control_output_cache.aspx

, , , , , .

+5

Source: https://habr.com/ru/post/1719730/


All Articles