View Source Cachetastic (Cachetastic v0.1.2)
Cachetastic main module for interacting with the cache.
This module provides a unified interface for various caching mechanisms such as ETS and Redis, with built-in fault tolerance. It allows you to perform basic caching operations like put, get, delete, and clear.
Configuration
You can configure the backends and fault tolerance settings in your config/config.exs
:
use Mix.Config
config :cachetastic,
backends: [
ets: [ttl: 600],
redis: [host: "localhost", port: 6379, ttl: 3600]
],
fault_tolerance: [primary: :redis, backup: :ets]
Examples
# Start the cache
{:ok, _pid} = Cachetastic.start_link()
# Perform cache operations
Cachetastic.put("key", "value")
{:ok, value} = Cachetastic.get("key")
Cachetastic.delete("key")
Cachetastic.clear()
Summary
Functions
Clears all values from the cache.
Deletes a value from the cache by key.
Gets a value from the cache by key.
Puts a value in the cache with the specified key and optional TTL.
Starts the cache with the primary backend.
Functions
Clears all values from the cache.
Deletes a value from the cache by key.
Gets a value from the cache by key.
Puts a value in the cache with the specified key and optional TTL.
Starts the cache with the primary backend.