serialization - AppFabric 缓存 - 我可以指定用于所有对象的序列化样式吗?

标签 serialization configuration caching appfabric appfabric-beta-2

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

我遇到了一个问题,当我放入缓存时,AppFabric 在一个类上运行 IXmlSerializable 实现,而我宁愿强制它使用二进制文件。 AppFabric Caching - What are its serialization and deserialization requirements for an object?

我可以配置这个吗?

(目前的解决方法是以编程方式将对象序列化为 byte[],然后将其发送到缓存中,在退出时反转该过程)。

最佳答案

在 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);

希望这可以帮助。

关于serialization - AppFabric 缓存 - 我可以指定用于所有对象的序列化样式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3756480/

相关文章:

c# - 对于新的 .net 核心应用程序,我应该在 protobuf-net 和 google.protobuf 之间使用什么 NuGet 包?

.net - 具有多态对象的数组的 JSON 序列化

java - Netbeans 平台应用程序中的 OSGi 配置管理服务

javascript - 如何使用 javascript 或 jQuery 预加载具有多个 srcset 的图像?

c++ - std::vector 中的每个元素访问都是缓存未命中吗?

ajax - 如何防止 IE 缓存导致重复的 Ajax 请求?

c++ - 如何将包含嵌入空值的 Google Protocol Buffer SerializeAsString() 输出分配给 std::string?

java - 为什么要在实体类中实现序列化

django - 在Django settings.py中导入文件时出现问题

.net - 如何以编程方式向 ConfigurationElementCollection 添加元素?