Antipattern: Store data greater than 512kb size in cache

Apigee Edge 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 512kb. The cache size of 512kb is the recommended size for optimal performance.

Antipattern

This particular antipattern talks about the implications of exceeding the current cache size restrictions within the Apigee Edge platform.

When data > 512kb 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 > 512kb are not available in L2 cache.
  • Storing larger data (> 512kb) 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 > 512kb 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 < 512kb in cache to get optimum performance.
  • If there’s a need to store data > 512kb, then consider:
    • Using any appropriate database for storing large data

      OR

    • Compressing the data

Further reading