Json Serializer does serialize whole CompressedResult of Cache, instead of effective Object

Hi,

I’m facing an issue using ServiceStack v5.4.1 while using the ServerSide Caching Feature (Request.ToOptimizedResultUsingCache).

public object Get(AvailableCryptoRequest request)
        {
            var cacheKey = "CryptoTerminal:InfoService:AvailableCryptoRequest";
            var cacheDuration = TimeSpan.FromHours(1);
            try
            {
                return base.Request.ToOptimizedResultUsingCache(base.Cache, cacheKey, cacheDuration, () =>
                {
                   // ... create new response object
                   return new ApiResponse<object>() {
                        Result = 1245
                   };
                });
            }
            catch (Exception ex)
            {
                var a = 4;

                return null;
            }
        }

If I call this service with Content-Type JSON, the service seems to serialize the whole Compressed Cache Result, instead of only the stored object (the ApiResponse).
However, calling this with a JSV-Content-Type, or without any Header at all, the response seems to be returned correctly (without a caching-object wrapper).

I’m using the Cache-Functionality on another part of the project as well (SS 5.2.0) where everything works fine.
Any possibility that this is a bug?

Best,
Daniel

Hi,

I accidentally also cached the HttpResult Object (which then wrapped the ApiResponse), which threw some exceptions.
Everything works as expected now - sorry about the confusion.

Best,
Daniel

1 Like