ZuploZuplo
LoginStart for Free
  • 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
    CORSEnvironment VariablesBranch-Based DeploymentsTestingTroubleshootingGitOps vs TerraformCustom Code
    Local Development
    Guides
      Advanced Path MatchingAPI VersioningOpenAPI Server URLsConvert URLs to OpenAPIOpenAPI Extension DataPath Modification ScriptsOpenAPI OverlaysCanary Routing for EmployeesGeolocation Backend RoutingUser-Based Backend RoutingBypass a PolicyTesting GraphQL QueriesHealth ChecksPerformance TestingTroubleshooting Slow ResponsesNon-Standard PortsHandling FormDataS3 Signed URL UploadsCheck IP AddressLazy Load ConfigurationSharing Code Across ProjectsBackstage IntegrationGitHub Action Automation
Policies
Handlers
API Keys
MCP Server
MCP Gateway
AI Gateway
Developer Portal
Monetization
Deploying & Source Control
Observability
Networking & Infrastructure
Account Management
Programming API
Build with AI
Zuplo CLI
Migration Guides
Platform LimitsSecuritySupportTrust & ComplianceChangelog
powered by Zudoku
Guides

Lazy Load Configuration

Often when working with a programmable gateway like Zuplo you'll want to load some configuration and store it safely for fast access on future requests without impacting latency.

The fastest place to store such information is in memory, but there can be thousands of processes on Zuplo when you're at scale and sometimes those processes aren't long lived.

The next fastest place is in ZoneCache which is a cache located in each data center. This requires an asynchronous connection but is usually much faster than going back to your configuration data store (often in a single location worldwide).

The MemoryZoneReadThroughCache offers the best of both worlds - it uses memory and zone cache in combination to afford the lowest possible latency.

Do take care not to load so much data into memory that you OOM (out-of-memory) your process. Processes in Zuplo typically have ~120MB of memory to perform all their work, including holding request bodies etc.

Here's a simple example of the usage of MemoryZoneReadthroughCache being used to store configuration data.

Code
import { ZuploContext, ZuploRequest, MemoryZoneReadThroughCache, environment, } from "@zuplo/runtime"; interface MyConfig { data: Record<string, string>[]; } const cacheName = "CACHE_NAME"; const configKey = "CONFIG_KEY"; const cacheTtlSeconds = 3600; async function loadConfig(context: ZuploContext) { // We will type the cache to work with MyConfig type, but // you can use `any` if there. Use the same cache name // when trying to use the same cache store from different modules. const cache = new MemoryZoneReadThroughCache<MyConfig>(cacheName, context); let config = await cache.get(configKey); if (!config) { // This is where you load the configuration for your own backend API const response = await fetch(`https://your-backend-config-api.com`, { headers: { authorization: `Bearer ${environment.CONFIG_API_KEY}`, }, }); if (response.status !== 200) { throw new Error( `Error reading config ${response.status}: '${await response.text()}'`, ); } config = await response.json(); cache.put(configKey, config, cacheTtlSeconds); } return config; } export default async function (request: ZuploRequest, context: ZuploContext) { const config = await loadConfig(context); context.log.info(config); // use the config in your pipeline or request handler etc // ... // ... return request; }
Edit this page
Last modified on March 27, 2026
Check IP AddressSharing Code Across Projects
TypeScript