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.

Errors

If preparing the tmp cache directory fails.

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, on an SSD, or similar, so operations are fast.

Errors

If preparing the cache directory under root_dir fails.

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.

Errors

If looking up, deserializing, executing, or serializing the command fails. This generally reflects a user error such as an invalid command.

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().

Errors

If looking up, deserializing, executing, or serializing the command fails. This generally reflects a user error such as an invalid command.

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.

Errors

If executing or serializing the command fails. This generally reflects a user error such as an invalid command.

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.

Errors

The Result returned by joining indicates whether there were any unexpected errors while cleaning up. It should be Ok in all normal circumstances.

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.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.