Phlex.FIFOCacheStore (phlex v0.3.0)

Copy Markdown View Source

An extremely fast in-memory cache store that evicts keys on a first-in-first-out basis.

This cache store is useful for caching rendered component fragments and attribute strings to improve performance in production environments.

Example

defmodule MyComponent do
  use Phlex.HTML

  defp cache_store do
    Phlex.FIFOCacheStore.new(max_bytesize: 1_048_576) # 1MB
  end
end

Summary

Functions

Returns the current size of the cache in bytes.

Clears all entries from the cache.

Fetches a value from the cache, or executes the function and caches the result.

Creates a new FIFO cache store.

Returns the number of entries in the cache.

Functions

bytesize(store)

Returns the current size of the cache in bytes.

clear(store)

Clears all entries from the cache.

fetch(store, key, fun)

Fetches a value from the cache, or executes the function and caches the result.

new(opts \\ [])

Creates a new FIFO cache store.

Options

  • :max_bytesize - Maximum total size in bytes (default: 1MB)

size(store)

Returns the number of entries in the cache.