Script Page - sendToGateway and CacheReponse

The CacheResponse attribute doesn’t seem to work when a script page calls sendToGateway. I am probably missing something, how can I make this work?

If I add a breakpoint in the service it is always called.

     {{  {id} |> sendToGateway('PostRequest', {catchError:'ex'}) |> to => p }}

        [CacheResponse(Duration =10)]
        public object Get(PostRequest req)
             var posts = GhostPostRequest(new PostQueryRequest() { Filter = $"id:{req.Id}" });
             if (posts.Posts.Count != 1) throw HttpError.NotFound($"Post does not exist");
             return posts.Posts[0];

No it’s only going to enable caching on HTTP Requests. You’d need to cache within your Service implementation like using the ToOptimizeResultsUsingCache APIs.

I tried that first but it didn’t work as it returns a compressed result. Am I missing something?

Right that returns the most optimal result for a HTTP Client which is typically a compressed result, you’d need to use an object cache like a CacheClient or Concurrent Dictionary:

return Cache.GetOrCreate(cacheKey, () => ...); //registered ICacheClient
return LocalCache.GetOrCreate(cacheKey, () => ...); // Memory Cache
1 Like

Got it, I’ll do it manually.