solution for caching update
well, well. interesting night!
first, i was able to solve my static (file) content caching issue by creating an in-memory cached copy of the item that has a dependency to the disk file as well as a callback method for when the ite falls out of the cache. i store the item with the complete URL (HttpContext.Current.Request.Url.AbsoluteUri
as the cache key and use that to fire off a new HEAD, Cache-Control:no-cache
. that works fine for almost all cases, but not quite. and that is the start of another challenge - Accept
headers!
yep, it's not enough to clear the cache based on the current request. any other possible entries (based on the SupportedMediaTypes
collection) need to be removed as well. it took me a bit to work that out, but it's all fine. i just code the ContentType
w/ the url as the cache key and then 'unpack' the ContentType
in the callback before making the HEAD
request. not too bad.
but then i found a whopper.
while doing some regression testing of the SqlXmlHandler
i discovered that almost 50% of my background cache items for a resource were *not* being cleared. i could Ctrl-F5 them (sending the "no-cache" header) just fine, but they no longer properly cleared out upon PUT, POST, DELETE
methods. and the reason was - you guessed it - media types.
see, *some* of the background cache clearing that needs to happen for a data update is going to be against resources that are not the same media type as the data update. in other words, when i send a data update using text/xml
, i will need to clear several resources that are also text/xml
. but i also need to clear some text/html
resources, too! and the list can continue. my cache URI collection will (likely) have mixed media types [sigh].
i came up with a solution for now, but it might need to be re-thought. when i build the ImmediateCacheUri
and BackgroundCacheUri
collections, i can optionally override the calling classes media type by adding it to the URI. it looks like this:
this.ImmediateCacheUri = new string[] { "/data/weblogs/?sparse", "/data/weblogs/?all", "/data/weblogs/{@id}", "/data/weblogs/", "/data/weblogs/?recent", "/blogging/<text/html>", "/blogging/m/<text/html,text/vnd.wap.wml>" };
now, when i design a resource class that needs to do cache clearing against other resources, there is a way to make sure that all proper media types are handled. it would be better if the cache clearing service could inquire against the resource definitions to get this data instead of coding it directly. maybe this can be done using reflection code...