3

We have an ASP.NET MVC application which currently is using .NET MemoryCache. The MemoryCache is fast and efficient, mostly because it does not clone or serialize data but essentially is storing references to objects.

Recently our client decided that we need scaling. To test how our application behaves when run in multiple processes, our web admin configured the app pool to use more than one worker process (so called "web garden" mode). Our cache started returning different results, depending on which worker process was serving current request.

We couldn't think of any simple way to synchronously clean up cached entries form MemoryCache instances for all worker processes (there seems to be no IIS API which would let us enumerate all worker processes of our app and call some "CleanUp" method for each app instance). So we decided to move to something more serious - memcached, which also will later let us set up the cache on a dedicated Linux server.

It was easy to install memcached and get started with Enyim .NET client. But then we got stopped by the fact that we cannot cache everything right away as we did with MemoryCache. Now we need to serialize everything. At first we tried .NET BinaryFormatter (which is being used by Enyim by default), but it requires [Serializable] attribute on each of our objects, and we just cannot spend much time crawling all our codebase and marking every object with [Serializable]. Another problem - we don't want to serialize all the private fields and props as BinaryFormatter does. In every other aspect BinaryFormatter is the best we can get - it is able to handle everything we throw at it.

Then we tried the well-known protobuf-net. Sorry, Marc, but it did not work for us, it needs too much of metadata configuration.

We don't need serializer with version control or back-compatibility because we can just clean the cache when we deploy a new release. We have lots of various kinds of cacheable objects, but nothing too fancy, no LINQ expressions, no observable collections nor other kinds of objects which usually seem to be problematic for most serializers out there.

Is there a simple but production ready replacement for BinaryFormatter, which can be globally configured to serialize only public fields and props and store them efficiently (I guess - binary)? Something "initialize and forget", something that does not need any attributes or other kinds of schema definitions, and which is able to deal with nullables, enumerables, custom types, boxed objects in the same way as BinaryFormatter does?

4

1 回答 1

2

看看Sharpserializer。它看起来很不错,但有一些扭结。

于 2013-08-27T21:09:22.393 回答