Class AiCacheStore

java.lang.Object
org.egothor.methodatlas.AiCacheStore

public final class AiCacheStore extends Object
Reads and writes the unified AI result cache as a JSON Lines file: one AiCacheEntry per line.

JSON Lines is chosen over a single JSON array so the file streams, appends cleanly, and a single corrupt line degrades to one lost cache entry rather than an unreadable file. The format is independent of the stable per-method scan CSV (which cannot carry credential verdicts or a prompt signature) and of the separate credential CSV; it is the sole carrier of cache state.

This class is a stateless, thread-safe utility holder.

Since:
4.1.0
  • Method Details

    • looksLikeJsonLines

      public static boolean looksLikeJsonLines(Path file) throws IOException
      Returns true if file appears to be a unified JSON-Lines cache rather than a legacy scan CSV, by inspecting the first non-whitespace byte.
      Parameters:
      file - path to inspect; never null
      Returns:
      true when the first non-blank character is an opening brace
      Throws:
      IOException - if the file cannot be read
    • read

      public static List<AiCacheEntry> read(Path file) throws IOException
      Reads all cache entries from a JSON-Lines file. Blank lines are ignored and a single unparseable line is skipped (logged at FINE) so a partially corrupt cache never aborts a scan.
      Parameters:
      file - path to the cache file; never null
      Returns:
      the parsed entries in file order; never null; may be empty
      Throws:
      IOException - if the file cannot be read
    • write

      public static void write(Path file, Collection<AiCacheEntry> entries) throws IOException
      Writes cache entries to a JSON-Lines file, one entry per line, overwriting any existing file. Parent directories are created if absent.
      Parameters:
      file - destination path; never null
      entries - entries to write; never null
      Throws:
      IOException - if the file cannot be written