Antipola: Menyimpan data berukuran lebih dari 256 KB dalam cache
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Anda sedang melihat dokumentasi Apigee dan Apigee hybrid.
Lihat dokumentasi
Apigee Edge.
Apigee menyediakan kemampuan untuk menyimpan data dalam cache saat runtime untuk persistensi dan pengambilan yang lebih cepat.
Data awalnya disimpan dalam cache dalam memori Message Processor, yang disebut sebagai cache
L1.
Cache L1 dibatasi oleh jumlah memori yang dicadangkan untuknya sebagai persentase dari memori JVM.
Entri yang di-cache kemudian dipertahankan di cache L2, yang dapat diakses oleh semua Message
Processor. Detail selengkapnya dapat ditemukan di bagian di bawah.
Cache L2 tidak memiliki batas mutlak pada jumlah entri cache, tetapi ukuran maksimum entri yang dapat di-cache dibatasi hingga 256 KB.
Ukuran cache 256 KB adalah
ukuran yang direkomendasikan untuk performa yang optimal.
Antipola
Antipola khusus ini membahas implikasi dari melampaui batasan ukuran cache
saat ini dalam Apigee.
Jika data > 256 KB di-cache, konsekuensinya adalah sebagai berikut:
Permintaan API yang dijalankan untuk pertama kalinya di setiap Pemroses Pesan harus mendapatkan
data secara independen dari sumber asli (kebijakan atau server target), karena entri >
256 KB
tidak tersedia di cache L2.
Menyimpan data yang lebih besar (> 256 KB) di cache L1 cenderung memberikan lebih banyak tekanan pada resource
platform. Hal ini menyebabkan memori cache L1 terisi lebih cepat sehingga ruang yang tersedia untuk data lain menjadi lebih sedikit. Akibatnya, Anda tidak akan dapat menyimpan data dalam cache
seaktif yang Anda inginkan.
Entri yang di-cache dari Pemroses Pesan akan dihapus jika batas jumlah
entri tercapai. Hal ini menyebabkan data diambil dari sumber asli lagi di
Pemroses Pesan masing-masing.
Dampak
Data berukuran > 256 KB tidak akan disimpan di cache L2/persisten.
Panggilan yang lebih sering ke sumber asli (kebijakan atau server target) menyebabkan peningkatan latensi untuk permintaan API.
Praktik terbaik
Sebaiknya simpan data berukuran < 256 KB di cache untuk mendapatkan performa yang optimal.
Jika ada kebutuhan untuk menyimpan data > 256 KB, pertimbangkan:
Menggunakan database yang sesuai untuk menyimpan data besar
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)"]]