I need to cache a large number of map in memory. Each map will be associated with a key for lookup. I’m planning to use POCO‘s cache framework for this.
If I serialized each map into say JSON, would that reduce the memory footprint of each cached item? If it does, what kind of saving can I expect – 10%, 50%?
Would you recommend caching plain objects or JSON?
Generally, yes, caching as JSON would be more efficient, storage-wise, than C++ objects.
The only exception would be if you had an object with a bunch of, eg, int fields and you converted that to a JSON representation (either JSON “object” or JSON “array”) as character values. The JSON character representation could not be nearly as compact as the binary fields, all scrunched together in a single object.
But if you’re talking objects that contain lots of pointers to other objects (ie, the typical “object” representation of conceptual JSON) then the actual JSON will be probably between 2x and 8x more compact.