Ragex.Analysis.Cache (Ragex v0.10.1)

View Source

Persistence layer for code analysis results (issues).

Caches issue discovery results (dead code, security, smells, duplicates, etc.) alongside file fingerprints. On load, compares stored fingerprints with current file state to determine cache freshness.

Data is stored at ~/.cache/ragex/<project_hash>/analysis.etf.

Usage

# Save analysis results
:ok = Analysis.Cache.save(issues, "/path/to/project")

# Load cached results (validates freshness)
{:ok, issues} = Analysis.Cache.load("/path/to/project")
{:stale, cached_issues, changed_files} = Analysis.Cache.load("/path/to/project")

# Check cache freshness
Analysis.Cache.fresh?("/path/to/project")

Summary

Functions

Clears the analysis cache.

Checks if the analysis cache is fresh (all files unchanged).

Loads cached analysis results and validates freshness.

Saves analysis results to disk with file fingerprints.

Returns statistics about the analysis cache.

Functions

clear(project_path \\ nil)

@spec clear(String.t() | nil) :: :ok

Clears the analysis cache.

fresh?(path)

@spec fresh?(String.t()) :: boolean()

Checks if the analysis cache is fresh (all files unchanged).

load(path)

@spec load(String.t()) ::
  {:ok, map()} | {:stale, map(), [String.t()]} | {:error, term()}

Loads cached analysis results and validates freshness.

Parameters

  • path - Project path to validate against

Returns

  • {:ok, issues} - Cache is fresh, all files unchanged
  • {:stale, issues, changed_files} - Some files changed, returns cached issues + list of changed files
  • {:error, :not_found} - No cache exists
  • {:error, reason} - Failure

save(issues, path)

@spec save(map(), String.t()) :: :ok | {:error, term()}

Saves analysis results to disk with file fingerprints.

Parameters

  • issues - Map of issue categories to their results
  • path - Project path that was analyzed

Returns

  • :ok - Saved successfully
  • {:error, reason} - Failure

stats(project_path \\ nil)

Returns statistics about the analysis cache.