View Source LastCrusader.Cache.MemoryTokenStore (Last Crusader v0.11.0)
Simple ETS-based cache.
https://gist.github.com/raorao/a4bb34726af2e3fa071adfa504505e1d
Summary
Functions
Asynchronous call to cache a value at the provided key. Any key that can
be used with ETS can be used, and will be evaluated using ==
.
Returns a specification to start this module under a supervisor.
Asynchronous clears all values in the cache.
Callback implementation for GenServer.init/1
.
Sychronously reads the cache for the provided key. If no value is found, returns :not_found .
Sychronously reads the cache for the provided key. If no value is found, invokes default_fn and caches the result. Note: in order to prevent congestion of the RequestCache process, default_fn is invoked in the context of the caller process.
Starts a RequestCache process linked to the current process. See
GenServer.start_link/2
for details.
Types
Functions
@spec cache(cache_key(), cache_value()) :: :ok
Asynchronous call to cache a value at the provided key. Any key that can
be used with ETS can be used, and will be evaluated using ==
.
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec clear() :: :ok
Asynchronous clears all values in the cache.
Callback implementation for GenServer.init/1
.
@spec read(cache_key()) :: cache_value() | :not_found
Sychronously reads the cache for the provided key. If no value is found, returns :not_found .
Sychronously reads the cache for the provided key. If no value is found, invokes default_fn and caches the result. Note: in order to prevent congestion of the RequestCache process, default_fn is invoked in the context of the caller process.
@spec start_link(integer()) :: GenServer.on_start()
Starts a RequestCache process linked to the current process. See
GenServer.start_link/2
for details.
By default, every item in the cache lives for 6 hours.