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

发布于 2024-09-24 09:35:58 字数 298 浏览 0 评论 0原文

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

我遇到了一个问题,当我放入缓存时,AppFabric 在类上运行 IXmlSerialized 实现,而我宁愿强制它使用二进制文件。 AppFabric 缓存 - 对象的序列化和反序列化要求是什么?

我可以配置它吗?

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

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 where when I put to cache, AppFabric runs the IXmlSerializable implementation on a class when I would rather force it to go with binary. AppFabric Caching - What are its serialization and deserialization requirements for an object?

Can I configure this?

(At the moment the workaround is to serialize the object programatically to a byte[] and then send that into the cache, reversing the process on the way out).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流年里的时光 2024-10-01 09:35:58

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

希望这会有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文