【问题标题】:AppFabric Caching - Can I specify serialization style used for all objects?AppFabric 缓存 - 我可以指定用于所有对象的序列化样式吗?
【发布时间】:2011-04-14 23:07:36
【问题描述】:
【问题讨论】:
标签:
serialization
configuration
caching
appfabric
appfabric-beta-2
【解决方案1】:
在 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);
希望这会有所帮助。