Apigee provides the ability to store data in a cache at runtime for persistence and faster
retrieval.
The data is initially stored in the Message Processor's in-memory cache, referred to as L1
cache.
The L1 cache is limited by the amount of memory reserved for it as a percentage of the JVM
memory.
The cached entries are later persisted in L2 cache, which is accessible to all Message
Processors. More details can be found in the section below.
The L2 cache does not have any hard limit on the number of cache entries, however the maximum
size of the entry that can be cached is restricted to 256 KB.
The cache size of 256 KB is the
recommended size for optimal performance.
Antipattern
This particular antipattern talks about the implications of exceeding the current cache size
restrictions within Apigee.
When data > 256 KB is cached, the consequences are as follows:
API requests executed for the first time on each of the Message Processors need to get the
data independently from the original source (policy or a target server), as entries >
256 KB
are not available in L2 cache.
Storing larger data (> 256 KB) in L1 cache tends to put more stress on the platform
resources. It results in the L1 cache memory being filled up faster and hence lesser space being
available for other data. As a consequence, one will not be able to cache the data as
aggressively as one would like to.
Cached entries from the Message Processors will be removed when the limit on the number of
entries is reached. This causes the data to be fetched from the original source again on the
respective Message Processors.
Impact
Data of size > 256 KB will not be stored in L2/persistent cache.
More frequent calls to the original source (either a policy or a target server) leads to
increased latencies for the API requests.
Best practice
It is preferred to store data of size < 256 KB in cache to get optimum performance.
If there's a need to store data > 256 KB, then consider:
Using any appropriate database for storing large data
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eApigee uses a two-tiered caching system (L1 and L2) to store data for persistence and faster retrieval, with L1 being an in-memory cache and L2 being a persistent cache accessible to all Message Processors.\u003c/p\u003e\n"],["\u003cp\u003eThe L2 cache has a size limit of 256 KB per entry for optimal performance, and exceeding this limit results in the data not being stored in L2.\u003c/p\u003e\n"],["\u003cp\u003eCaching data larger than 256 KB causes API requests to fetch data independently from the original source on each Message Processor, and it also stresses the L1 cache, leading to less space available for other data.\u003c/p\u003e\n"],["\u003cp\u003eStoring data under 256 KB is the preferred practice for optimal caching performance, and for data exceeding this size, consider using a database or compressing the data.\u003c/p\u003e\n"],["\u003cp\u003eExceeding the cache size limit increases the frequency of calls to the original source and results in higher API request latency.\u003c/p\u003e\n"]]],[],null,["# Antipattern: Store data greater than 256 KB size in cache\n\n*You're viewing **Apigee** and **Apigee hybrid** documentation.\nView [Apigee Edge](https://docs.apigee.com/api-platform/antipatterns/caching-large) documentation.*\n\nApigee provides the ability to store data in a cache at runtime for persistence and faster\nretrieval.\n\n- The data is initially stored in the Message Processor's in-memory cache, referred to as *L1\n cache*.\n- The L1 cache is limited by the amount of memory reserved for it as a percentage of the JVM memory.\n- The cached entries are later persisted in *L2 cache*, which is accessible to all Message Processors. More details can be found in the section below.\n- The L2 cache does not have any hard limit on the number of cache entries, however the maximum *size* of the entry that can be cached is restricted to 256 KB. The cache size of 256 KB is the recommended size for optimal performance.\n\nAntipattern\n-----------\n\nThis particular antipattern talks about the implications of exceeding the current cache size\nrestrictions within Apigee.\n\nWhen data \\\u003e 256 KB is cached, the consequences are as follows:\n\n- API requests executed for the first time on each of the Message Processors need to get the data independently from the original source (policy or a target server), as entries \\\u003e 256 KB are not available in L2 cache.\n- Storing larger data (\\\u003e 256 KB) in L1 cache tends to put more stress on the platform resources. It results in the L1 cache memory being filled up faster and hence lesser space being available for other data. As a consequence, one will not be able to cache the data as aggressively as one would like to.\n- Cached entries from the Message Processors will be removed when the limit on the number of entries is reached. This causes the data to be fetched from the original source again on the respective Message Processors.\n\nImpact\n------\n\n- Data of size \\\u003e 256 KB will not be stored in L2/persistent cache.\n- More frequent calls to the original source (either a policy or a target server) leads to increased latencies for the API requests.\n\nBest practice\n-------------\n\n- It is preferred to store data of size \\\u003c 256 KB in cache to get optimum performance.\n- If there's a need to store data \\\u003e 256 KB, then consider:\n - Using any appropriate database for storing large data **OR**\n\n - Compressing the data\n\nFurther reading\n---------------\n\n- [Cache internals](/apigee/docs/api-platform/cache/cache-internals)"]]