Struct bkt::Bkt [−][src]
pub struct Bkt { /* fields omitted */ }
Expand description
This struct is the main API entry point for the bkt
library, allowing callers to invoke and
cache subprocesses for later reuse.
Implementations
Creates a new Bkt instance using the std::env::temp_dir
as the cache location.
Creates a new Bkt instance.
The given root_dir
will be used as the parent directory of the cache. It’s recommended
this directory be in a tmpfs partition, and SSD, or similar so operations are fast.
Associates a scope with this Bkt instance, causing it to namespace its cache keys so that they do not collide with other instances using the same cache directory. This is useful when separate applications could potentially invoke the same commands but should not share a cache. Consider using the application’s name, PID, and/or a timestamp in order to create a sufficiently unique namespace.
Looks up the given command in Bkt’s cache, returning it, and its age, if found and newer than the given TTL.
If stale or not found the command is executed and the result is cached and then returned. A zero-duration age will be returned if this invocation refreshed the cache. A background cleanup thread will also run on cache misses to remove stale data.
pub fn execute_without_cleanup(
&self,
command: &CommandDesc,
ttl: Duration
) -> Result<(Invocation, Duration)>
pub fn execute_without_cleanup(
&self,
command: &CommandDesc,
ttl: Duration
) -> Result<(Invocation, Duration)>
See the documentation on execute()
. This functions like execute()
but does not attempt
to clean up stale data. Prefer this method if you decide to manage cleanup yourself via
cleanup_once()
or cleanup_thread()
.
Unconditionally executes the given command and caches the invocation for the given TTL.
This can be used to “warm” the cache so that subsequent calls to execute
are fast.
Initiates a single cleanup cycle of the cache, removing stale data in the background. This
should be invoked by short-lived applications early in their lifecycle and then joined
before exiting. execute_and_cleanup
can be used instead to only trigger a cleanup on a
cache miss, avoiding the extra work on cache hits. Long-running applications should
typically prefer cleanup_thread
which triggers periodic cleanups.
Initiates an infinite-loop thread that triggers periodic cleanups of the cache, removing
stale data in the background. It is not necessary to join()
this thread, it will
be terminated when the main thread exits.