Skip to main content

Quick Start

Get started with @warlock.js/cache in under 30 seconds!

Installation

npm install @warlock.js/cache

30-Second Example

import { cache, MemoryCacheDriver, CACHE_FOR } from "@warlock.js/cache";

// Configure
cache.setCacheConfigurations({
default: "memory",
drivers: { memory: MemoryCacheDriver },
options: { memory: { ttl: CACHE_FOR.ONE_HOUR } }
});

await cache.init();

// Use
await cache.set("user.123", { name: "John" }, CACHE_FOR.HALF_HOUR);
const user = await cache.get("user.123");
await cache.remove("user.123");

That's it! You're now caching data.

Key Concepts

  • Drivers: Interchangeable storage backends (Memory, Redis, File, etc.)
  • TTL: Time-to-live in seconds (how long values stay cached)
  • Keys: Dot notation strings (e.g., "user.123", "posts.456.comments")
  • Namespaces: Hierarchical organization (e.g., users.profile.123)

Next Steps