1장. Configuring cache encoding
Find out how to configure Data Grid caches with different media types and how encoding affects the ways you can use Data Grid.
1.1. Cache encoding 링크 복사링크가 클립보드에 복사되었습니다!
Encoding is the format, identified by a media type, that Data Grid uses to store entries (key/value pairs) in caches.
Remote caches
Data Grid Server stores entries in remote caches with the encoding that is set in the cache configuration.
Hot Rod and REST clients include a media type with each request they make to Data Grid Server. To handle multiple clients making read and write requests with different media types, Data Grid Server converts data on-demand to and from the media type that is set in the cache configuration.
If the remote cache does not have any encoding configuration, Data Grid Server stores keys and values as generic byte[] without any media type information, which can lead to unexpected results when converting data for clients request different formats.
Use ProtoStream encoding
Data Grid Server returns an error when client requests include a media type that it cannot convert to or from the media type that is set in the cache configuration.
Data Grid recommends always configuring cache encoding with the application/x-protostream media type if you want to use multiple clients, such as Data Grid Console or CLI, Hot Rod, or REST. ProtoStream encoding also lets you use server-side tasks and perform indexed queries on remote caches.
Embedded caches
Data Grid stores entries in embedded caches as Plain Old Java Objects (POJOs) by default.
For clustered embedded caches, Data Grid needs to marshall any POJOs to a byte array that can be replicated between nodes and then unmarshalled back into POJOs. This means you must ensure that Data Grid can serialize your POJOs with the ProtoStream marshaller if you do not configure another marshaller.
If you store mutable POJOs in embedded caches, you should always update values using new POJO instances. For example, if you store a HashMap as a key/value pair, the other members of the Data Grid cluster do not see any local modifications to the Map. Additionally, it is possible that a ConcurrentModificationException could occur if the Map instance is updated at the same time that Data Grid is marshalling the object.