lib.FcCache: Add a write-through read cache #145
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20261017-lib-fccache-add-a-write-through-read-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds a write-through read cache in front of a file context. The two commits build on each other:
FcWrapperfirst establishes the delegation base — a context that adopts the identity of the wrapped context and forwards every primitive, so a derived context overrides only what it cares about — andFcCachethen implements the cache on top of it, so repeatedstat()andget()calls on a path pay the cache instead of the wrapped context, andwarm()pre-fills the cache with a single host command when the wrapped context is an exec context:lib.FcWrapper: Add a delegating file context wrapper
Add a file context that sits in front of another one and delegates every primitive call to it.
The wrapper adopts the identity of the wrapped context: uri, root, chroot flag, and the chroot path composition are the wrapped context's, so a path composed by the wrapper composes identically in the wrapped context. Every primitive is forwarded to the wrapped context's primitives, which receive the already-composed path;
open()andclose()are forwarded to the wrapped context's public methods, so the open count is kept in one place.The point is to give derived contexts a stable base: a caching context, or any other filter, overrides the primitives it cares about and inherits the rest, instead of re-deriving the chroot bookkeeping of every method.
lib.FcCache: Add a write-through read cache
Add a write-through read cache in front of a file context.
stat()andget()results are cached: stat per (path,follow_symlinks), get per (path, wd, throw). Successful stats andFileNotFoundErrorsare cached; other errors are re-probed, so a transient transport failure does not poison the cache. Writes pass through to the wrapped context and drop the cache entries of the affected paths. The existence and directory checks are rerouted through the cached stat, so they pay the cache instead of the wrapped context's own fast path.warm()fills the stat cache of a set of paths, asfile_exists()would stat them, without following symlinks. If the wrapped context is an exec context, one host command stats all of the paths; otherwise, one stat per path runs.The GNU stat format of
ExecContextis lifted to the module constantSTAT_GNU_FORMAT, and the field parser is exported asparse_stat_fields(), sowarm()fills entries that are indistinguishable from a realstat().