Programming Your Application to Use PdxInstances

Programming Your Application to Use PdxInstances

A PdxInstance is a lightweight wrapper around
the raw bytes of the PDX serialized objects kept in the cache. It
provides applications with run-time access to files of a PDX serialized
object. GemFire provides the implementation of the
PdxInstance class.

You can configure your cache to return a PdxInstance
when a PDX serialized object is deserialized instead of
deserializing the object to a domain class. Preventing
deserialization saves both time and memory and does not require you
deserialize the object to the domain class.

This configuration can be done in cache.xml by setting the attribute
read-serialized to true on the
<pdx>element. Or it can be done programmatically using the
CacheFactory::setPdxReadSerialized(bool)
method.

After this preference is configured, any time a PDX object is
deserialized, it is deserialized into a
PdxInstance.

The following is a code sample of using the setField API of
PdxInstance to modify fields:

In addition to field access, PdxInstance also
supports field modification using the
setField(fieldName) method. The
setField method has copy-on-write semantics. So
for the modifications to be stored in the cache, the
PdxInstance must be put into a region after
setField has been called one or more times.