FileSystemDirectoryCache

A LoadingDirectoryCache storing its entries as directories under a common root on the local file system, loading the missing ones through a CacheableDataLoader. It knows nothing about how data is obtained, depending only on CachedDirectoryKey.

Each entry is loaded at most once, even across processes sharing the same root: callers asking for an entry that is being loaded wait for the loading to complete and then find it in cache. Within a JVM, they synchronize on a monitor per entry; across processes, on an operating system lock of a file per entry, in the .locks directory under root. Different entries can still be loaded in parallel.

Loaded entries are published with an atomic move, so they are visible either completely or not at all. If file locks are not supported (as on some network file systems), processes do not wait for each other: all of them load the entry, the first one to publish it wins, and the others discard their own copy. This wastes work, but never corrupts the cache.

Note! Entries are trust-based: an existing directory is assumed to be complete and valid, and its content is not re-verified on a cache hit. Manual alteration of a cache entry is out of contract.

Parameters

loader

fills a cache entry whenever it is missing.

root

path of the cache root directory, created if missing.

Type Parameters

K

the type of CachedDirectoryKey accepted by this cache.

Constructors

Link copied to clipboard
constructor(loader: CacheableDataLoader<K>, root: Path)

Types

Link copied to clipboard
object Companion

Conventional locations and internal constants for the filesystem cache.

Functions

Link copied to clipboard
open operator override fun get(key: K): Path

Returns the directory associated with key, producing it if absent.