[id='sfs_cache_store']
= Single File Cache Stores
Single File cache stores, `SingleFileStore`, persist data to file. {brandname}
also maintains an in-memory index of keys while keys and values are stored in
the file. By default, Single File cache stores are segmented, which means that
{brandname} creates a separate file for each segment.

Because `SingleFileStore` keeps an in-memory index of keys and the location of
values, it requires additional memory, depending on the key size and the number
of keys. For this reason, `SingleFileStore` is not recommended for use cases
where the keys have a large size.

In some cases, `SingleFileStore` can also become fragmented. If the size of
values continually increases, available space in the single file is not used
but the entry is appended to the end of the file. Available space in the file
is used only if an entry can fit within it. Likewise, if you remove all entries
from memory, the single file store does not decrease in size or become
defragmented.

.Declarative configuration

[source,xml,options="nowrap",subs=attributes+]
----
<persistence>
   <file-store max-entries="5000"/>
</persistence>
----

.Programmatic configuration

* For embedded deployments, do the following:

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

* For server deployments, do the following:

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

.Segmentation

Single File cache stores support segmentation and create a separate
instance per segment, which results in multiple directories in the path you
configure. Each directory is a number that represents the segment to which the
data maps.

.Reference

* link:#setting_persistent_location-persistence[Setting a Global Persistent Location]
* link:{configdocroot}infinispan-config-{schemaversion}.html[{brandname} configuration schema]
* link:{javadocroot}/org/infinispan/persistence/file/SingleFileStore.html[SingleFileStore]
