Reputation: 306
I am involved in an effort to replace System.Web.Caching.Cache with Redis. The issue I am running into is that while System.Web.Caching.Cache seems to be able to cache just about whatever object I pass to it, Redis is string-based. This means that I have to worry about serialization myself.
The two approaches I've tried are 1) to use JSON.NET to serialize my objects to a string, and 2) to use BinaryFormatter. The JSON.NET approach can probably be made to work, but of course there are many configuration points (around what to serialize/ignore, how to handle reference loops, etc.) and making this approach work has turned into a fair amount of work.
The BinaryFormatter approach, I had suspected, was probably closer to what System.Web.Caching.Cache was doing internally. Having gone down that path a bit, though, I am not so sure of that anymore. Many types I'm trying to cache are not marked [Serializable], which seems to rule out BinaryFormatter.
I am wondering if anyone else has faced similar issues, or knows what System.Web.Caching.Cache is doing internally so that I can emulate it. Thanks.
Upvotes: 0
Views: 744
Reputation: 2062
System.Web.Caching.Cache seems to be able to cache just about whatever object I pass to it. This means that I have to worry about serialization myself.
That is exactly because System.Web.Caching.Cache
stores object references when application is running.
So that I can emulate it
Unfortunately, you cannot. Redis is a remote service. When you take advantage of Redis (i.e., distributed caching, reducing memory footprint in your local machine), you have to pay the price - handle serialization yourself.
The good news is that, there are a couple of serialization libraries available.
Upvotes: 1