[id='configure_off_heap-{context}']
= Configuring {brandname} to Store Cache Entries Off Heap
{brandname} can use either JVM heap memory or off-heap native memory as the
data container for cache entries. By default {brandname} stores cache entries
in JVM heap memory.

{brandname} can use off-heap storage with eviction based on the total number of
entries or maximum amount of memory. When using off-heap, {brandname} stores
cache entries in Protobuf format with the `application/x-protostream` encoding.

.Procedure

To store cache entries in off-heap memory, configure {brandname} in one of the
following ways:

* Declaratively: Add the `storage="OFF_HEAP"` attribute to the `memory` element.
* Programmatically: Call the `storage(OFF_HEAP)` method in the `MemoryConfigurationBuilder` class.

.Declarative example

[source,xml,options="nowrap"]
----
include::config_examples/max_size_offheap.xml[]
----

.Programmatic example

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

* link:{configdocroot}[{brandname} Configuration Schema Reference]
* link:{javadocroot}/org/infinispan/configuration/cache/MemoryConfigurationBuilder.html[org.infinispan.configuration.cache.MemoryConfigurationBuilder]
