CRi*_*ice 8 configuration serialization caching appfabric appfabric-beta-2
实现某些自定义序列化的对象可以序列化和反序列化为不同的格式,例如Xml或byte [].
我遇到了一个问题,当我放入缓存时,AppFabric在类上运行IXmlSerializable实现时,我宁愿强制它使用二进制. AppFabric缓存 - 对象的序列化和反序列化要求是什么?
我可以配置吗?
(目前,解决方法是以编程方式将对象序列化为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
}
}
Run Code Online (Sandbox Code Playgroud)
之后,您可以将自定义序列化程序设置为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);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
2079 次 |
| 最近记录: |