实现某些自定义序列化的对象可以被序列化并应为不同的格式,例如xml或byte []。

我遇到了一个问题,当我进入缓存时,appFabric在我宁愿强迫它与二进制的情况下运行IXMLSerializable实现。 AppFabric缓存 - 其对象的序列化和应有的要求是什么?

我可以配置吗?

(目前,解决方法是将对象序列化至字节[],然后将其发送到缓存中,并在出路时逆转过程)。

有帮助吗?

解决方案

在MSDN文档中,它说我们可以实现IdatacacheObjectSerializer以实现此目标。你可以在这里读到它: 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
    }
}

您可以将自定义序列化器设置为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);

希望这可以帮助。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top