[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.
+
* Declarative: Set the `max-count` attribute.
* Programmatic: Call the `maxCount()` method.
+
. Configure an eviction strategy to control how {brandname} removes entries.
+
* Declarative: Set the `when-full` attribute.
* Programmatic: Call the `whenFull()` method.


.Declarative configuration
[source,xml,options="nowrap",subs=attributes+,role="primary"]
----
include::config_examples/max_count_memory.xml[]
----

.Programmatic configuration
[source,java,options="nowrap",subs=attributes+,role="secondary"]
----
include::code_examples/MaxCountMemory.java[]
----

[role="_additional-resources"]
.Additional resources
* link:{configdocroot}[{brandname} Configuration Schema Reference]
* link:{javadocroot}/org/infinispan/configuration/cache/MemoryConfigurationBuilder.html[org.infinispan.configuration.cache.MemoryConfigurationBuilder]
