[id='eviction_example-{context}']
= Eviction Examples

Configure eviction as part of your cache definition.

.Default memory configuration

Eviction is not enabled, which is the default configuration. {brandname} stores cache entries as objects in the JVM heap.

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

.Eviction based on the total number of entries

{brandname} stores cache entries as objects in the JVM heap. Eviction happens when there are 100 entries in the data container and {brandname} gets a request to create a new entry:

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

.Eviction based maximum size in bytes

{brandname} stores cache entries as `byte[]` arrays if you encode entries with binary storage formats, for example: `application/x-protostream` format.

In the following example, {brandname} performs eviction when the size of the data container reaches 500 MB (megabytes) in size and it gets a request to create a new entry:

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

.Off-heap storage

{brandname} stores cache entries as bytes in native memory.
Eviction happens when there are 100 entries in the data container and {brandname} gets a request to create a new entry:

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

.Off-heap storage with the exception strategy

{brandname} stores cache entries as bytes in native memory.
When there are 100 entries in the data container, and {brandname} gets a request to create a new entry, it throws an exception and does not allow the new entry:

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

.Manual eviction

{brandname} stores cache entries as objects in the JVM heap. Eviction is not enabled but performed manually using the `evict()` method.

[TIP]
====
This configuration prevents a warning message when you enable passivation but do not configure eviction.
====

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

.Passivation with eviction

Passivation persists data to cache stores when {brandname} evicts entries.
You should always enable eviction if you enable passivation, for example:

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

.References

* link:#passivation[Passivation]
