views:

299

answers:

2

Is it possible to clear the output cache of one asp.net web application from inside another asp.net web application?

Reason being... We have several wep applications structured like...

Pages in /area1/ and /area2/ are cached and are managed through /intranet/cms/. When a page is edited using /intranet/cms/ I want to clear it out of the cache in the appropriate /area#/ application.

I already tried using a VaryByCustom that looks up a guid stored in the HttpContext.Cache but that seems to be cached per web application, that doesn't work.

Really if there were any way of passing data between web applications on a single server, that would solve my problem, since I can use that + VaryByCustom.

Thanks!

-Mike Thomas

+2  A: 

One way I know of doing this is by using a shared resource as a dependency, usually a file. When the file is changed, the cache is cleared. I think you can use HttpResponse.AddFileDependency for this.

However, in these cases it's usually better to use an out-of-process cache such as memcached. I haven't tested it myself, but this link deals on using memcached with OutputCache.

Badaro
Interesting possibility. I'm not a huge fan of having a large number of essentially "temp" files chilling on the server (since we want to be able to invalidate individual pages), but it it does seem viable. Since this is all still on a single server, the extra administrative overhead of setting up an external caching provider isn't quite worth it, but that *would* do the trick.
Mike
+2  A: 

The way I've done this in the past is to have a "hidden" page (in each of the /areaX sites) that does the flushing, reloading, etc. The page validates a shared secret query parameter before doing anything (to avoid DoS attacks). If valid the page would output an "OK" message once the operation is complete; generates a 404 error if the secret is invalid.

If you want the flush to be on a per-item or per-group basis then add a second parameter that identifies that item/group.

This method is also server technology independent, and can be triggered by other management tools if required.

devstuff
Good idea - I was (and still am) considering this. Issuing a http request from the "editing" area is (in my mind) less than ideal, but it would surely work.
Mike
This is a viable solution as long as you don't use multiple worker processes (Web Garden).
Badaro
@Badaro: good point, I'll have to remember that one. I don't run any of my apps in a web garden at the moment, but just use multiple server load balancing.
devstuff