[id='encoding']
= Cache encoding
Encoding is the format, identified by a media type, that {brandname} uses to store entries (key/value pairs) in caches.

[discrete]
== Remote caches

{brandname} 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 {brandname} Server.
To handle multiple clients making read and write requests with different media types, {brandname} 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, {brandname} 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

{brandname} 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.

{brandname} recommends always configuring cache encoding with the `application/x-protostream` media type if you want to use multiple clients, such as {brandname} Console or CLI, Hot Rod, or REST.
ProtoStream encoding also lets you use server-side tasks and perform indexed queries on remote caches.

[discrete]
== Embedded caches

{brandname} stores entries in embedded caches as Plain Old Java Objects (POJOs) by default.

For clustered embedded caches, {brandname} 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 {brandname} can serialize your POJOs with the ProtoStream marshaller if you do not configure another marshaller.

[NOTE]
====
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 {brandname} 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 {brandname} is marshalling the object.
====

[role="_additional-resources"]
.Additional resources
* link:{protostreamdocroot}[{brandname} ProtoStream API]
