Vaultx.Cache.L2 (Vaultx v0.7.0)

View Source

L2 Distributed Cache implementation.

This module provides distributed caching capabilities using external storage systems like Redis or Memcached. It's designed for sharing cache data across multiple VaultX instances in a cluster environment.

Features

  • Distributed Storage: Share cache across multiple nodes
  • Persistence: Survives application restarts
  • Scalability: Handle large datasets beyond memory limits
  • Network Optimization: Efficient serialization and compression
  • Failover Support: Graceful degradation when L2 is unavailable

Supported Adapters

  • Redis (recommended for production)
  • Memcached (for simple use cases)
  • Custom adapters via behaviour implementation

Performance Characteristics

  • Read latency: ~1-5ms (network dependent)
  • Write latency: ~2-10ms (network dependent)
  • Throughput: Limited by network and storage backend
  • Memory usage: Minimal (data stored externally)

Configuration

config :vaultx, :cache,
  l2_adapter: Vaultx.Cache.Adapters.Redis,
  l2_connection: [
    host: "localhost",
    port: 6379,
    database: 0,
    pool_size: 10
  ],
  l2_ttl_default: :timer.hours(1),
  l2_compression: true,
  l2_encryption: false

Summary

Functions

Returns a specification to start this module under a supervisor.

Performs cleanup of expired entries.

Clears L2 cache.

Deletes a value from L2 cache.

Gets a value from L2 cache.

Puts a value into L2 cache.

Starts the L2 cache.

Gets L2 cache statistics.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

cleanup()

Performs cleanup of expired entries.

clear(pattern \\ :all)

Clears L2 cache.

delete(key)

Deletes a value from L2 cache.

get(key)

Gets a value from L2 cache.

put(key, value, opts \\ [])

Puts a value into L2 cache.

start_link(config)

Starts the L2 cache.

stats()

Gets L2 cache statistics.