Skip to main content

Introduction

Cache is a crucial part of any high-performance application. It stores frequently accessed data, reducing database or API calls and improving response times.

Why Use Cache?

  • Speed: Serve data instantly from memory or fast storage.
  • Scalability: Reduce load on databases and external services.
  • Cost: Lower infrastructure costs by reducing repeated expensive operations.

Cache Manager

Warlock provides a unified, developer-friendly API to interact with cache. The CacheManager lets you use any cache driver with a consistent set of methods.

Available Cache Drivers

Warlock ships with several drivers out of the box:

  1. Redis Cache Driver — Best for distributed, production-grade caching.
  2. Database Cache Driver — Store cache in your database for persistence and querying.
  3. File Cache Driver — Simple, persistent, file-based cache.
  4. Memory Cache Driver — Fast, in-memory cache (resets on restart).
  5. Memory Extended Cache Driver — Like memory, but resets TTL on every access (sliding expiration).
  6. LRU Memory Cache Driver — In-memory cache with Least Recently Used eviction.
  7. Null Cache Driver — Disables caching (useful for testing).

Quick Guide: Which Driver Should I Use?

Use CaseRecommended Driver
Production, multi-server, distributedRedis
Need database persistence with queryingDatabase
Local development, simple persistenceFile
Fastest, ephemeral, single-processMemory
Need sliding expirationMemory Extended
Limited memory, want LRU evictionLRU Memory
Testing, disable cacheNull

Advanced Features

  • Namespaces for grouping cache keys
  • Global Prefixes to avoid key collisions
  • Custom Drivers: Create your own
  • Driver Switching: Change drivers at runtime
  • Multi-driver strategies (coming soon)
  • Built-in Logging: All cache operations are automatically logged
  • TTL Management: Automatic expiration handling

Ready to get started? Check out Cache Configurations or jump to a driver above!