Localize.FormatCache (Localize v0.26.0)

Copy Markdown View Source

An ETS-backed cache for compiled format patterns.

Number format metadata and datetime format tokens are cached here after first compilation. A built-in sweeper periodically evicts random entries when the cache exceeds its configured maximum size.

The maximum number of entries defaults to 2,000 and can be overridden with:

config :localize, :format_cache_max_entries, 5_000

Summary

Functions

Returns a specification to start this module under a supervisor.

Look up a compiled format pattern by its cache key.

Store a compiled format pattern in the cache.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

lookup(key)

@spec lookup(term()) :: {:ok, term()} | :miss

Look up a compiled format pattern by its cache key.

Arguments

  • key is the cache key, typically a tuple like {:localize, :number_format_meta, format_string}.

Returns

  • {:ok, value} if the key is present.

  • :miss if not cached or the table does not exist.

store(key, value)

@spec store(term(), term()) :: :ok

Store a compiled format pattern in the cache.

Arguments

  • key is the cache key.

  • value is the compiled artifact to cache.

Returns

  • :ok.