[id='configuring_cache_stores-{context}']
= Configuring Cache Stores
Add cache stores to {brandname} caches in a chain either declaratively or
programmatically. Cache read operations check each cache store in the
configured order until they locate a valid non-null element of data. Write
operations affect all cache stores except for those that you configure as read
only.

.Procedure

. Use the `persistence` parameter to configure the persistence layer for caches.
. Configure whether cache stores are local to the node or shared across the cluster.
+
Use either the `shared` attribute declaratively or the `shared(false)` method programmatically.
+
. Configure other cache stores properties as appropriate. Custom cache stores can also include `property` parameters.
+
[NOTE]
====
Configuring cache stores as shared or not shared (local only) determines which
parameters you should set. In some cases, using the wrong combination of
parameters in your cache store configuration can lead to data loss or
performance issues.

For example, if the cache store is local to a node then it makes sense to fetch
state and purge on startup. However, if the cache store is shared, then you
should not fetch state or purge on startup.
====

.Local (non-shared) file store

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

.Shared custom cache store

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

.Single file store

[source,java]
----
include::code_examples/SingleFileStore.java[]
----

.Reference

* link:{configdocroot}[{brandname} Configuration Schema]
* link:#cache_store_implementations[{brandname} Cache Store Implementations]
* link:#create_custom_cache_store[Creating Custom Cache Stores]
