[id='configure_eviction_total-{context}']
= Configuring the Total Number of Entries for {brandname} Caches
Limit the size of the data container for cache entries to a total number of
entries.

.Procedure

. Configure your {brandname} cache encoding with an appropriate storage format.
. Specify the total number of entries that caches can contain before
{brandname} performs eviction.
+
* Declaratively: Set the `max-count` attribute.
* Programmatically: Call the `maxCount()` method.
+
. Configure an eviction strategy to control how {brandname} removes entries.
+
* Declaratively: Set the `when-full` attribute.
* Programmatically: Call the `whenFull()` method.


.Declarative example

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

.Programmatic example

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

.Reference

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