Metastatic.Cache behaviour (Metastatic v0.28.0)

View Source

AST Caching behaviour and dispatcher for Metastatic.

Caches the results of parsing and abstracting source code to MetaAST (M2). Supports multiple backends (ETS, DLLB), configured via :metastatic, :cache.

Default backend is :ets.

Summary

Functions

Clear all cached entries from the active cache backend.

Get cached abstraction result (MetaAST + Metadata) for a source code string and language.

Return the configured cache implementation module.

Initialize the active cache backend. Called automatically during application startup.

Store abstraction result in cache.

Callbacks

clear()

@callback clear() :: :ok

get(adapter, source)

@callback get(adapter :: module(), source :: String.t()) ::
  {:ok, term(), map()} | {:error, :not_found}

init()

@callback init() :: :ok

put(adapter, source, meta_ast, metadata)

@callback put(
  adapter :: module(),
  source :: String.t(),
  meta_ast :: term(),
  metadata :: map()
) :: :ok

Functions

clear()

@spec clear() :: :ok

Clear all cached entries from the active cache backend.

get(adapter, source)

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

Get cached abstraction result (MetaAST + Metadata) for a source code string and language.

impl()

@spec impl() :: module()

Return the configured cache implementation module.

Options for :metastatic, :cache are:

init()

@spec init() :: :ok

Initialize the active cache backend. Called automatically during application startup.

put(adapter, source, meta_ast, metadata)

@spec put(module(), String.t(), term(), map()) :: :ok

Store abstraction result in cache.