Selecto.Performance.QueryCache (Selecto v0.3.16)

High-performance query result caching for Selecto.

Provides intelligent caching of query results with:

  • Automatic cache key generation from SQL and parameters
  • TTL-based expiration
  • Size-based eviction (LRU)
  • Cache invalidation strategies
  • Cache statistics and monitoring
  • ETS-backed low-latency reads

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Clear entire cache.

Generate a cache key from Selecto query.

Generate a cache key from SQL and parameters.

Get a cached query result.

Invalidate cache entries by key or pattern.

Invalidate cache entries by tags.

Store a query result in cache.

Start the query cache process.

Get cache statistics.

Warm up cache with frequently used queries.

Link to this section Functions

Link to this function

cached_execute(selecto, execute_fn, options \\ [])

Execute a query with caching.

This is a convenience function that checks cache, executes if needed, and caches the result.

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Clear entire cache.

Link to this function

generate_key(selecto)

Generate a cache key from Selecto query.

Link to this function

generate_key_from_sql(sql, params)

Generate a cache key from SQL and parameters.

Get a cached query result.

Returns {:ok, result} if found, :miss if not in cache.

Link to this function

invalidate(key_or_pattern)

Invalidate cache entries by key or pattern.

Link to this function

invalidate_by_tags(tags)

Invalidate cache entries by tags.

Link to this function

put(cache_key, result, options \\ [])

Store a query result in cache.

options

Options

  • :ttl - Override default TTL for this entry
  • :tags - Tags for cache invalidation
  • :compress - Force compression for this entry
Link to this function

start_link(opts \\ [])

Start the query cache process.

options

Options

  • :max_size - Maximum number of cached queries (default: 1000)
  • :default_ttl - Default TTL in milliseconds (default: 5 minutes)
  • :eviction_policy - :lru, :lfu, or :ttl (default: :lru)
  • :cache_backend - :ets (default: :ets)
  • :track_stats - Enable cache statistics (default: true)
  • :compression - Enable result compression (default: false)

Get cache statistics.

Link to this function

warmup(queries)

Warm up cache with frequently used queries.