Question on recent commit "Don't process cache for InProcess requests"

I have a lot of “common” service requests, which semi-static lookup tables, they are hybrid cached locally, as they are called many times internally during a single complex service request and the Redis transmission time started to become an obvious performance burden.

I had planned on converting a number of calls we have caching on to the new CacheAttribute but many of them are called InProcess as well as externally and prior to this commit it appeared as if I could retrieve a cached response InProcess in which case everything should just work as expected (granted I hadn’t yet tried beyond a bit of fiddling with a sample project a few weeks ago).

I’m just wondering what the reasoning behind making this change was. As it stands now I might have to reconsider my plans.

Short-circuiting a response with a 304 or writing raw compressed bytes to the response stream doesn’t work when it’s called in-process from a ServiceGateway which needs access to “untouched” original DTO’s.

So you’d only use Cache features for external API calls, for internal calls you can still add caching for internal in-process requests by storing DTO’s in the base.LocalCache which as it’s an in-memory cache it doesn’t have any network or serialization overhead, e.g:

public object Any(Request request)
{
    var cacheKey = request.ToGetUrl();
    return base.LocalCache.GetOrCreate(cacheKey, TimeSpan.FromMinutes(1), 
        () => new Response { ... } );
}

Makes sense. I’ll just keep them as they are implemented, then add the Attribute when I’m ready to start using client-side caching for my external clients. I just will have to remember to also invalidating the date:{cacheKey} key when invalidating a service request cache.

What’s an appropriate caching strategy for services the are called in-process and externally? Which SS features are recommend in this scenario?

The above example works for both internal and external requests.

I was thinking about a strategy that would cater for both internal and external requests without comprising the optimal solution for external requests (short-circuited optimized responses). Combining CacheResponse and base.LocalCache like this might work for me.

[CacheResponse(Duration = 600)]
public object Get(Hello request)
{
	Func<HelloResponse> hello = () => new HelloResponse
	{
            Result = "Hello, {0}!".Fmt(request.Name)
	};

	if (!Request.IsInProcessRequest())
                return hello();

	var cacheKey = request.ToGetUrl();
	return base.LocalCache.GetOrCreate(cacheKey, TimeSpan.FromMinutes(10), hello);
}