Partial Caching AddCacheItemDependency problem

I have a very stupid and simple project, just for testing, with only
one page (default.aspx), and one user control. The user control only
shows the time in an asp:literal each time the page is requested.

I want to cache the content of the user control (not the entire page),
and I want to invalidate that cache when I need. To do this, I have
added an "OuputCache" directive in my USER control. Furthermore I have
a button to invalidate the cache. This is the user control code:

Well, it does not work. All my attemps to invalidate the cache of the
user control have been unsucessfull. Only if I put the "OutputCache"
directive in the default.aspx (what means cache the entire page) the
cache invalidation mechanism works.

Advertisements

You cannot call the AddCacheItemDependency method in an ASP.NET user
control. However, in any user control that specifies the @ OutputCache
directive, you can create a CacheDependency object that describes the
cache key dependency and assign it to the Dependency property of the
UserControl object.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!