Question

Un objet qui implémente une sérialisation personnalisée peut être sérialisé et désérialisé différents formats, par exemple pour Xml ou octet [].

J'ai couru dans un problème où quand je mets le cache, AppFabric exécute la mise en œuvre IXmlSerializable sur une classe quand je préférerais le forcer à aller avec binaire. AppFabric Caching - Quelles sont les exigences de sérialisation et désérialisation pour un objet

?

Puis-je configurer cela?

(Au moment de la solution consiste à sérialiser l'objet d'un octet programatically [], puis l'envoyer dans le cache, inverser le processus à la sortie).

Était-ce utile?

La solution

Dans la documentation MSDN, il dit que nous pourrions mettre en œuvre IDataCacheObjectSerializer pour atteindre cet objectif. Vous pouvez lire ici: 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, vous pouvez définir le sérialiseur personnalisé au 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top