Caching compressed data from WCF on IIS

292 Views Asked by At

I have a WCF service hosted on IIS. Size of responses are quite big so I require a dynamic data compression that is enabled on IIS side (Service uses wsHttpBinding).

At some point I realize that I need caching of the compressed data too. Each of the requests to server is unique but return only one of few possible values. That means that I can't use IIS Caching because each request is different. On the other hand I can't use WCF caching because it doesn't know anything about IIS compressing, so we have to re-compress cached data over and over again.

Is there a way to work with a IIS compressed data cache from WCF/.net code? Any other known solutions?

3

There are 3 best solutions below

0
On BEST ANSWER

Given that you say that your payload is large, I will assume that an extra round trip will add negligible latency. I would therefore suggest that you that you take full advantage of the fact that you are on HTTP.

Write a service behavior that detects that you are on HTTP. Then once you determine which of the large objects you are "returning", you intercept the return call, and replace it with a HttpContext.Response.Redirect().

Then write a separate service to host the ACTUAL results as a HTTP GET with a deterministic URL.

The advantages you will get.

  1. You can cache using IIS again (potentially faster implementation of caching)
  2. Reverse Proxy Caching works as well
  3. Your client's ISP proxy cache works too
  4. Your client's OS/Browser caching works as well
  5. Heck, the proxy could even do the decompression for clients that do not support GZIP

The pattern described here is HTTP redirection to a Canonical URL.

Simples!

PS Try to use the 303 redirect if possible

2
On

Please read the article: http://www.codeproject.com/Articles/53718/Extending-WCF-Part-II . Hope this is helpful for you.

1
On

You can create your own cache. Create a static read-only field referencing a Dictionary. Protect the Dictionary with lock blocks. Store in the dictionary a mapping from the request value (the value in the request that determines the result) to cache id, where cache id is a filename, or other identifier to look up the file. Or, if in memory, the actual cached object or blob. All of the cached files or blobs would be compressed already so you don't have to do that.

You cannot use the IIS compression in this case.