I need to invalidate cache entries held by a WAS-hosted WCF service. The wrinkle is that the invalidation trigger comes from an external process. I have considered the following approaches:
- Use System.Runtime.Caching.MemoryCache with timed cache entry expiration. This won't work for me because changes to the cache's underlying data do not happen on a schedule and I must not ever return stale data.
- Add an "administrative"
InvalidateCache()
method on my WCF service to invalidate the cache that could be invoked by the external process when appropriate. This would be workable if the WCF service were not WAS-hosted. In other words, if the app were idle and unloaded by WAS, invoking theInvalidateCache()
method would unnecessarily activate it. I looked for ways that I might query WAS for the state of the service and conditionally callInvalidateCache()
only if the service were active, but I could find no such APIs for WAS. - Use a Windows named event as the mechanism for triggering cross-process cache invalidation. I think the WCF service could be configured to listen for a named event and invalidate its own cache in response, but that seems like an unnecessarily complicated solution to a common problem.
Is there a better approach or something that would make one of the three approaches above workable?