Raxol.Terminal.Buffer.CacheManager (Raxol v0.5.0)

View Source

Manages caching for the terminal buffer system. Provides efficient caching mechanisms for frequently accessed buffer regions.

Summary

Functions

Gets a value from the cache.

Invalidates a cache entry.

Creates a new cache manager with the specified maximum size.

Puts a value in the cache.

Gets cache statistics.

Types

cache_entry()

@type cache_entry() :: %{
  data: term(),
  last_access: integer(),
  access_count: non_neg_integer()
}

cache_key()

t()

@type t() :: %Raxol.Terminal.Buffer.CacheManager{
  cache: %{required(cache_key()) => cache_entry()},
  current_size: non_neg_integer(),
  hit_count: non_neg_integer(),
  max_size: non_neg_integer(),
  miss_count: non_neg_integer()
}

Functions

get(cache, key)

Gets a value from the cache.

Parameters

  • cache - The cache manager instance
  • key - The cache key

Returns

  • {:ok, value} - The cached value if found
  • :miss - If the value is not in cache

invalidate(cache, key)

Invalidates a cache entry.

Parameters

  • cache - The cache manager instance
  • key - The cache key to invalidate

Returns

  • Updated cache manager instance

new(max_size \\ 1000)

Creates a new cache manager with the specified maximum size.

Parameters

  • max_size - Maximum number of cache entries (default: 1000)

Returns

  • A new cache manager instance

put(cache, key, value)

Puts a value in the cache.

Parameters

  • cache - The cache manager instance
  • key - The cache key
  • value - The value to cache

Returns

  • Updated cache manager instance

stats(cache)

Gets cache statistics.

Parameters

  • cache - The cache manager instance

Returns

  • Map containing cache statistics