Antipattern: memorizzare nella cache dati di dimensioni superiori a 256 KB
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Stai visualizzando la documentazione di Apigee e Apigee hybrid.
Visualizza la documentazione di
Apigee Edge.
Apigee offre la possibilità di archiviare i dati in una cache in fase di esecuzione per la persistenza e un recupero più rapido.
I dati vengono inizialmente archiviati nella cache in memoria del processore di messaggi, denominata cache L1.
La cache L1 è limitata dalla quantità di memoria riservata come percentuale della memoria JVM.
Le voci memorizzate nella cache vengono successivamente mantenute nella cache L2, accessibile a tutti gli elaboratori di messaggi. Per ulteriori dettagli, consulta la sezione di seguito.
La cache L2 non ha un limite fisso per il numero di voci della cache, ma la dimensione massima della voce che può essere memorizzata nella cache è limitata a 256 KB.
La dimensione della cache di 256 KB è la dimensione consigliata per un rendimento ottimale.
Antipattern
Questo particolare antipattern illustra le implicazioni del superamento delle attuali limitazioni di dimensione della cache in Apigee.
Quando i dati di dimensioni superiori a 256 KB vengono memorizzati nella cache, le conseguenze sono le seguenti:
Le richieste API eseguite per la prima volta su ciascun Message Processor devono recuperare i dati indipendentemente dall'origine originale (criterio o server di destinazione), poiché le voci >
256 KB
non sono disponibili nella cache L2.
L'archiviazione di dati più grandi (> 256 KB) nella cache L1 tende a mettere a dura prova le risorse della piattaforma. Di conseguenza, la memoria della cache L1 viene riempita più velocemente e quindi lo spazio disponibile per altri dati è minore. Di conseguenza, non sarà possibile memorizzare nella cache i dati in modo così aggressivo come si vorrebbe.
Le voci memorizzate nella cache dei processori dei messaggi verranno rimosse quando viene raggiunto il limite per il numero di voci. Di conseguenza, i dati vengono recuperati di nuovo dall'origine originale sui rispettivi elaboratori di messaggi.
Impatto
I dati di dimensioni superiori a 256 KB non verranno memorizzati nella cache L2/persistente.
Chiamate più frequenti all'origine originale (un criterio o un server target) comportano un aumento delle latenze per le richieste API.
Best practice
Per ottenere prestazioni ottimali, è preferibile memorizzare in cache i dati di dimensioni inferiori a 256 KB.
Se è necessario archiviare dati di dimensioni superiori a 256 KB, valuta la possibilità di:
Utilizzo di qualsiasi database appropriato per l'archiviazione di dati di grandi dimensioni
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 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)"]]