These docs are for v2.0. Click to read the latest docs for v7.0.

Silhouette caches some authentication artifacts. Here are some suggestions
on configuring or implementing caching in your application architecture
so that Silhouette can also use it.

Implement caching

By default, Play is shipped with EHCache, a lightweight, in-memory cache. If this is not enough for your application architecture, there are at least two other caching options to use with Silhouette.

Use another Play cache plugin

Play has its own cache plugin architecture. So the easiest approach is to use another cache plugin for Play. You can then use the PlayCacheLayer implementation and plug a new cache into your application.

Implement your own cache layer

Silhouette provides a CacheLayer trait which can be used to create a custom cache implementation.

Clustered environment

If you use a clustered environment for your application then make sure that you use a distributed cache like Redis or Memcached. Otherwise cached artifacts must be synchronized between instances.

Development mode

When using the default Play cache in development mode, the cache will be cleaned after every app reload. This is because Play's cache (EHCache) is configured to store the data only in memory by default. This can be changed by overriding the shipped ehcache.xml from the jars to persist the cache on the disk.

To change the default behavior you must copy the ehcache.xml from the distribution jars to your configuration directory. Then add <diskStore path="java.io.tmpdir"/> and change diskPersistent to true. The following example shows a possible configuration. Adapt it to fit your needs.

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"
    updateCheck="false">

    <diskStore path="java.io.tmpdir"/>
    <defaultCache
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="120"
        timeToLiveSeconds="120"
        overflowToDisk="false"
        maxElementsOnDisk="10000000"
        diskPersistent="true"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU"
    />
</ehcache>

📘

Note

You can also get around this issue by using a distributed cache like Redis or Memcached.