Skip to main content

Module file

Module file 

Source
Expand description

The file driver: one file per key under a configurable directory.

Useful when a single-process application wants a cache that survives a restart without running Redis. Two properties matter more than speed here:

  • A key can never escape the directory. Cache keys routinely contain user input (user:{email}, a URL, a path), so the file name is a hash of the key, not the key. ../../etc/passwd and a/b/c become 32 hex characters like everything else.
  • A reader never sees half a write. Payloads are written to a temporary file and renamed into place, which is atomic on every platform rustlavel targets.

The hash is FNV-1a rather than DefaultHasher because DefaultHasher is explicitly allowed to change between Rust releases: an upgrade would silently orphan every file on disk.

Structsยง

FileStore
A cache stored on disk. Cloning shares one directory and one lock table.