Caching of JSON response duplicates data in db - why?

Hi. I am running a dirt-simple site on a very low end machine, that basically proxies other data, which takes a long time to query/process. I stash all that into a MySQL db for speed improvement on subsequent client requests, but because of the low-end plan I a bought, I have a max of 10GB per db.

Basically: I want to use the cache functionality, but limit the cache table size as much as possible by not creating redundant records, if at all possible, to squeeze as many cached endpoint responses as possible into the db, given that I only serve JSON.

I saw in another cache ticket you mentioned that if the cache table hit 900MB for one guy, he experienced troubles on azure, so I started digging into my existing data.

Just out of curiousity, I note that I receive only JSON requests, but the cache logic from SS (pasted below, from CacheClientExtensions.cs) seems to make 3 records per endpoint… one “mycachekey”, one “mycachekey.json” and one “mycachekey.json.deflate” (as well as a corresponding .deflate.created record. – BUT… the first call to cache.set is saving the object, which is / happens to be the json of the output anyway… so why bother duplicating this? Can I / should I be able to save only one of either the cached object OR json … and skip the effectively-duplicated db entries? I don’t quite understand the case where I’d want/need to have both object and serialised json in the db?

Thanks

      public static object Cache(this ICacheClient cacheClient,
        string cacheKey,
        object responseDto,
        IRequest request,
        TimeSpan? expireCacheIn = null)
    {

        request.Response.Dto = responseDto;
    // dale sees this caching the object, maybe can skip this?
        cacheClient.Set(cacheKey, responseDto, expireCacheIn);

        if (!request.ResponseContentType.IsBinary())
        {
            string serializedDto = SerializeToString(request, responseDto);

            string modifiers = null;
            if (request.ResponseContentType.MatchesContentType(MimeTypes.Json))
            {
                var jsonp = request.GetJsonpCallback();
                if (jsonp != null)
                {
                    modifiers = ".jsonp," + jsonp.SafeVarName();
                    serializedDto = jsonp + "(" + serializedDto + ")";

                    //Add a default expire timespan for jsonp requests,
                    //because they aren't cleared when calling ClearCaches()
                    if (expireCacheIn == null)
                        expireCacheIn = HostContext.Config.DefaultJsonpCacheExpiration;
                }
            }
    // dale sees this cachcing the serialized json, can i skip this? 
            var cacheKeySerialized = GetCacheKeyForSerialized(cacheKey, request.ResponseContentType, modifiers);
            cacheClient.Set(cacheKeySerialized, serializedDto, expireCacheIn);

The first cache (i.e. without format/encoding extension) is a cache of the DTO object, what format the underlying caching provider chooses to use is an internal implementation detail, e.g. the Memory Cache client doesn’t serialize the DTO at all.