[id='configuring_cache_encoding-{context}']
= Configuring Encoding for {brandname} Caches
Define the MediaType that {brandname} uses to encode your data when writing and
reading to and from the cache.

[TIP]
====
When you define a MediaType, you specify the format of your data to {brandname}.

If you want to use the {brandname} Console, Hot Rod clients, and REST clients
interchangeably, specify the `application/x-protostream` MediaType so
{brandname} encodes data in Protobuf format.
====

.Procedure

* Specify a MediaType for key and values in your {brandname} cache configuration.
** Declaratively: Set the `encoding` attribute.
** Programmatically: Use the `encoding()` method.

.Declarative examples

* Use the same encoding for keys and values:

[source,xml,options="nowrap",subs=attributes+]
----
include::config_examples/cache_encoding.xml[]
----

* Use a different encoding for keys and values:

[source,xml,options="nowrap",subs=attributes+]
----
include::config_examples/encoding_media_type.xml[]
----

.Programmatic examples

* Use the same encoding for keys and values:

[source,java,options="nowrap"]
----
include::code_examples/CacheEncoding.java[]
----

* Use a different encoding for keys and values:

[source,java,options="nowrap"]
----
include::code_examples/EncoderMediaType.java[]
----
