TTLDatastore creates a new datastore that supports TTL expirations.
The underlying Datastore to wrap with TTL expirations.
A Datastore to use for storing TTL information. Will default to a
NamespaceDatastore that stores all TTL metadata in the input store
under a ttl
prefix.
If you don't want to mix your metadata with your keys, consider provider your own store directly.
A set of options for controlling the underlying TTL mechanics.
The underlying Datastore to wrap with TTL expirations.
batch returns a Batch object with which you can chain multiple operations.
The operations are only executed upon calling commit
. Any put
operation on a batch
will use the supplied TTL value.
close the datastore. This should always be called to ensure resources are cleaned up. This will wait until the TTL timer has been cleared before resolving.
delete removes the content stored under the given key.
The key.
expiration returns the expiration UTC timestamp in milliseconds for a given key.
The key.
get retrieves the value stored under the given key.
The key.
has checks for the existence of a given key.
The key.
open the datastore. This is only needed if the store was closed before, otherwise this is taken care of by the constructor. If a store is reopened, the TTL timing is not automatically restarted (@see startTTL).
put stores a value with the given key.
The key.
The value.
The time-to-live, in milliseconds. Defaults to options.ttl
.
query searches the store for key/value pairs matching a given query.
Object describing the query parameters.
startTTL starts the underlying TTL timer. This is called by default upon datastore initialization, but can be used to restart a the TTL timer after stopTTL has been called (@see stopTTL).
stopTTL clears the underlying TTL timer. If stopped, keys will no longer expire, but any new entires will still be given TTL values, which may expire after the timer is restarted (@see startTTL).
ttl inserts or updates a TTL for a given key.
The key.
The time-to-live, in milliseconds. Defaults to options.ttl
.
TTLDatastore is an implementation of the Datastore interface that supports a time-to-live (TTL) for datastore entries. After the TTL expires on a given key, the entry will be automatically cleared from the datastore unless it is refreshed in the mean time. In this way you can build utilities like session managers where a given session is refreshed with each interaction but expires after a set period of time since the last interaction.
TTLDatastore borrows ideas from https://github.com/Level/level-ttl.