ZuploZuplo
LoginSign Up
  • Documentation
  • API Reference
Introduction
Getting Started
    Develop using the Portal
      1 - Setup Your Gateway2 - Rate Limiting3 - API Key Auth4 - Deploy5 - Dynamic Rate LimitingMCP - Quick start
    Develop Locally
      1 - Setup Your Gateway2 - Rate Limiting3 - API Key Auth
Concepts
Development
Policies
Handlers
API Keys
MCP Server
MCP Gateway
AI Gateway
Developer Portal
Monetization
Deploying & Source Control
Observability
Networking & Infrastructure
Account Management
Programming API
    Overview
    Request & Context
    Configuration
    Caching APIs
      ZoneCacheMemoryZoneReadThroughCacheStreamingZoneCacheCache
    Data Management
    Extensions & Hooks
    Error Handling
    Logging & Observability
    Types and Interfaces
    Web Standards
    Advanced Topics
Build with AI
Zuplo CLI
Migration Guides
Platform LimitsSecuritySupportTrust & ComplianceChangelog
powered by Zudoku
Caching APIs

MemoryZoneReadThroughCache

The MemoryZoneReadThroughCache class provides an in-memory caching solution with automatic read-through capabilities. This cache stores data in memory for fast access and automatically handles cache misses.

Constructor

Code
new MemoryZoneReadThroughCache<T = unknown>(name: string, context: ZuploContext)

Creates a new instance of the memory cache with read-through capabilities.

  • name - A unique identifier for the cache instance
  • context - The ZuploContext object
  • T - The type of data stored in the cache (defaults to unknown)

Methods

get

Retrieves a value from the cache by its key. Returns undefined if not found.

Code
get(key: string): Promise<T | undefined>

put

Stores a value in the cache with a time-to-live (TTL) in seconds.

Code
put(key: string, data: T, ttlSeconds: number): void

delete

Removes a value from the cache.

Code
delete(key: string): Promise<void>

Example

Code
import { MemoryZoneReadThroughCache, ZuploContext, ZuploRequest, } from "@zuplo/runtime"; export default async function handler( request: ZuploRequest, context: ZuploContext, ) { // Create a cache instance for user data const userCache = new MemoryZoneReadThroughCache<{ name: string; email: string; }>("user-cache", context); // Try to get user from cache const userId = "user-123"; let user = await userCache.get(userId); if (!user) { // User not in cache, fetch from database user = await fetchUserFromDatabase(userId); // Cache the user data for 5 minutes (300 seconds) userCache.put(userId, user, 300); } return new Response(JSON.stringify(user)); }

Best Practices

  • Use descriptive cache names to avoid collisions between different cache instances
  • Set appropriate TTL values based on your data freshness requirements
  • Consider memory usage when caching large objects
  • The cache is scoped to the current worker instance and not shared across instances

See Also

  • ZoneCache - For distributed caching across zones
  • StreamingZoneCache - For caching streaming data
  • BackgroundLoader - For automatic cache population
Edit this page
Last modified on August 8, 2025
ZoneCacheStreamingZoneCache
On this page
  • Constructor
  • Methods
  • Example
  • Best Practices
  • See Also
TypeScript
TypeScript
TypeScript
TypeScript
TypeScript