Should I cache json, Bson or JObject in the ICacheManager? Should I cache json, Bson or JObject in the ICacheManager? json json

Should I cache json, Bson or JObject in the ICacheManager?


I pursued this on github where, long story short, I ended up caching the json string and JObject.Parse it on retrieval.

The pertinent question to ask was "are you using a distributed cache?" I am, and I'm also using a local cache.

If I was only using a local cache, I could put the JObjects straight in the cache as no serialization is involved.

When using a distributed cache however, you actually cannot place a JObject into it since that type isn't serializable (no SerializableAttribute).

When using both, you're constrained by the requirements of both, meaning you're left with caching the json strings and parsing them on retrieval.

It is possible that one could use the CacheManager.Serialization.Json package to swap out the serialization mechanism. But I'd rather keep the binary serializer in my scenario as I'm mostly caching POCO's and a binary serializer should be more efficient in general. I don't think using this would net me any performance gains anyway, since the built-in serializer would have to transform the JObjects to json internally anyway.

In conclusion: By keeping the binary serializer and caching the json as strings I don't lose out on performance, but I do have to add a few JObject.Parse(..) here and there when reading from the cache. With decent encapsulation, that's not an issue.