简体   繁体   中英

Save a C# object to disk without serializing it?

We have an existing asp.net 4.0 website that uses the HttpRuntime.Cache for a lot of things. It was created like this before I started working on it and now we're having problems with the cache being cleared and the website falling over because it always expects the cache to be there (I know... what did they think a cache was!?).

So what I need is a replacement cache that is permanent so I can swap it for the HttpRuntime.Cache with no impact to the website. I've looked at serialization but not all the objects are serializable and it's not an option to make them all serializable (there are way too many of them scattered all over).

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

Update:

Thanks for your comments and answer so far. Starting with your ideas I did some more Googling and came across this article that demonstrates (with an example solution you can download) how to use your own custom caching provider in .Net 4.0. I haven't been able to integrate it into our web application and give it a proper test yet (hopefully later today I'll be able to) but I thought I'd put it here to see if you have any thoughts about it... so what do you think, any caveats I should be aware of? Or is this a viable (and very temporary) solution?

File-Based Cache for Web and non-Web Apps plus Extend ASP.NET 4.0 OutputCacheProvider

You can write own "serialization" using reflections, get all primitive fields and save it as class path and value. it will be long operation but you will can save class as file. Better solution is use real serialization.

This link did work, so it's going to be my answer. Thanks for everyone's help!

File-Based Cache for Web and non-Web Apps plus Extend ASP.NET 4.0 OutputCacheProvider

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM