Store (v6.6)

In some cases, a cache mechanism is required. In pac4j, this is defined by the Store concept.

It has the following methods:

It has the following implementations, and you may provide your own if necessary:

val store = new ConcurrentMapStore<String, String>(5, TimeUnit.MINUTES);

When the stored values carry their own expiration date, extend the AbstractConcurrentMapStore and read the date from the value: there is then a single lifetime to define instead of two which must agree.

public class MyStore extends AbstractConcurrentMapStore<String, MyValue> {

    @Override
    protected Instant expiresAt(final MyValue value) {
        return value.getExpiresAt();
    }
}

The expiration date is computed once, when the value is stored: changing it afterwards is only taken into account on the next set. Returning null keeps the entry forever.

Entries are dropped when they expire: when they are read and when another value is stored. Neither of these two stores runs a background thread.