Services.FileCache (fnord v0.9.29)

View Source

GenServer-backed file cache used by AI tools and other services that need to read file contents from the project workspace.

Responsibilities:

  • Store {path -> %{sha: sha, content: content}}
  • Provide lookup and insert APIs
  • Handle concurrent access safely via GenServer

The cache is intentionally simple: it validates freshness by recomputing a sha256 over the file contents when doing a lookup and updates the stored entry when a mismatch is detected.

Summary

Functions

Returns a specification to start this module under a supervisor.

Lookup a cached file by absolute path. Returns {:ok, content} or :miss. The caller should provide a fetch_fun that will be called to obtain actual file contents when the cache is missing or stale.

Directly put content into the cache for a path.

Types

entry()

@type entry() :: %{sha: String.t(), content: String.t()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_or_fetch(path, fetch_fun)

@spec get_or_fetch(String.t(), (-> {:ok, String.t()} | {:error, any()})) ::
  {:ok, String.t()} | {:error, any()} | :miss

Lookup a cached file by absolute path. Returns {:ok, content} or :miss. The caller should provide a fetch_fun that will be called to obtain actual file contents when the cache is missing or stale.

put(path, content)

@spec put(String.t(), String.t()) :: :ok

Directly put content into the cache for a path.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()