AppFabric Caching - Can I specify serialization style used for all objects?

后端 未结 1 1816
后悔当初
后悔当初 2021-01-12 06:10

An object which implements some custom serialization can be serialized and deserialized to different formats, for example to Xml or byte[].

I have run into a problem

相关标签:
1条回答
  • 2021-01-12 07:04

    In the MSDN documentation it says we could implement IDataCacheObjectSerializer to achieve this goal. You can read about it here: http://msdn.microsoft.com/en-us/library/windowsazure/hh552969.aspx

    class MySerializer : IDataCacheObjectSerializer
    {
        public object Deserialize(System.IO.Stream stream)
        {
            // Deserialize the System.IO.Stream 'stream' from
            // the cache and return the object 
        }
    
        public void Serialize(System.IO.Stream stream, object value)
        {
            // Serialize the object 'value' into a System.IO.Stream
            // that can be stored in the cache
        }
    }
    

    Afer that, you can set the custom serializer to the DataCacheFactory:

    DataCacheFactoryConfiguration configuration = new DataCacheFactoryConfiguration();
    
    configuration.SerializationProperties = 
       new DataCacheSerializationProperties(DataCacheObjectSerializerType.CustomSerializer, 
       new MyNamespace.MySerializer());
    
    // Assign other DataCacheFactoryConfiguration properties...
    
    // Then create a DataCacheFactory with this configuration
    DataCacheFactory factory = new DataCacheFactory(configuration);
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题