An In-Memory, Write-Only, Header-Only, Key-Value Cache Library
- Include
include/ephemera.h
. - The
libpthread
library is required (seeMakefile
for compilation options). - User must provide a data type for the template (see
include/data.h
for an example). Optionally the user should provide a custom output stream function for their data type.
- Create an instance of
Ephemera<T> ec;
, where isT
is the user supplied data type to be stored. - Spawn the cache expiry thread:
std::thread cacheExpiry(Ephemera<T>::cacheExpiryLoop, std::ref(ec));
- After spawning cache expiry thread, the following:
cacheExpiry.join();
will block until the cache expiry thread re-joins the main thread. - A signal handler should be used to set
Ephemera<T>::Active
tofalse
to shutdown the cache expiry thread gracefully. - To insert a new key-value pair:
bool success = ec.set(key, value, ttl);
(the default ttl is 60 seconds) - To retrieve the value for a key:
bool found = ec.get(key, &value);
- Simple API:
set
andget
- User-specified data type
- Does not include commands to update or delete a key.
- Negative expiry times are not permitted.
- See examples in the
src
directory - To build examples, run:
make all