1

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:

  1. 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.
  2. 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 the InvalidateCache() method would unnecessarily activate it. I looked for ways that I might query WAS for the state of the service and conditionally call InvalidateCache() only if the service were active, but I could find no such APIs for WAS.
  3. 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?

Steve Lillis
  • 3,263
  • 5
  • 22
  • 41
Dan Hermann
  • 1,107
  • 1
  • 13
  • 27
  • 1
    `2. [...] invoking the InvalidateCache() method would unnecessarily activate it` - this one does not look too bad for me. Why wouldn't you go with it? – alex.b May 19 '14 at 20:19
  • @aleksey.berezan The WCF service provides on-demand info about a server process on the same host. If no users require info about the server process, I would like the WCF service to be unloaded so as not to use take up computing resources that could be used by the server process. – Dan Hermann May 19 '14 at 21:13
  • does cache work in scope of the same process as service or in separate one? – alex.b May 19 '14 at 23:29
  • @aleksey.berezan The cache lifetime and cache entry invalidation are controlled by the server process which is separate from the WCF service. – Dan Hermann May 20 '14 at 12:05
  • @Don, in such case there's another approach: to create separate "administrative" WCF-service with InvalidateCache() method. – alex.b May 20 '14 at 16:45

0 Answers0