Save a C # object to disk without serializing it?

We have an existing asp.net 4.0 site that uses HttpRuntime.Cache for many things. It was created this way before I started working on it, and now we have problems clearing the cache, and the site crashes because it always expects the cache to be there (I know ... what they thought the cache was !?).

So, I need a spare cache, which is permanent, so I can change it to HttpRuntime.Cache without affecting the site. I looked at serialization, but not all objects are serializable, and it’s not possible to make them all serializable (there are too many of them scattered all over).

Is there a way to save any object / memory variable / to disk and read it later without having to serialize it?

Update:

Thanks for your comments and answers. Starting with your ideas, I did a few more Googling and came across this article, which demonstrates (using an example solution that you can download) how to use your own custom caching provider in .NET 4.0. I was not able to integrate it into our web application and give it another test (I hope I can do it later), but I thought I put it here to find out if you have any thoughts on this. .. so do you think any warnings I should be aware of? Or is this a viable (and very temporary) solution?

File-based cache for web and non-web applications plus ASP.NET 4.0 extension OutputCacheProvider

+4
source share
2 answers

This link really worked, so that will be my answer. Thanks for the help!

File-based cache for web and non-web applications plus ASP.NET 4.0 extension OutputCacheProvider

0
source

You can write your own β€œserialization” using reflections, get all the primitive fields and save them as the class path and value. it will be a lengthy operation, but you can save the class as a file. The best solution is to use real serialization.

+5
source

Source: https://habr.com/ru/post/1446874/


All Articles