API Services exposes a Cache resource that can be used at runtime to persist data across transactions.
There are three main reasons for using a cache:
- To reduce latency: The request is satisfied from the cache (which is closer to the client) instead of the origin server, so the cache gets the representation and displays it in a shorter time. This makes the server more responsive.
- To reduce network traffic: Representations are reused, so the impact of processing duplicate or redundant requests is reduced. Cache reduces the amount of bandwidth you use, which decreases bandwidth requirements overall.
- To persist data across transactions: Session data can be stored for reuse across HTTP transactions.
You can create multiple Cache resources in each environment. For data segregation, the scope of a Cache is limited to an environment in which the cache is created. (For example, API proxies running in a 'test' environment cannot access data in a cache running in 'prod'.) Once the cache is created, it can be populated with any serializable data by using cache policies. For usage, see Optimize performance using Cache.
A default cache resource is configured for every organization. Under ordinary circumstances, you do not need to explicitly configure a cache. Only configure a cache when you need to customize the Cache settings and optimize performance. If you have questions about your cache resource configuration, contact Apigee Support.
See also: Reduce latency using ResponseCache.
Navigate to environment configuration
From the main menu, select Environment Configuration from the APIs drop-down:
A drop-down menu displays a list of all available environments in your organization. Select the environment whose caches you need to view or edit.
Select the Add a Cache button:
Enter configuration settings for cache
A form displays that enables you to configure a cache. The form is shown below. Configuration settings are described in the table below the image.
Modifying a cache configuration
A cache configuration has the following properties:
|Property Name||Default Value||Description|
||mycache||The name of the cache. Must be unique in the environment. Reference this cache from policies that interact with the cache resource.|
||N/A||An optional description of the cache resource.|
||Timeout in Seconds||Enables different expiration mechanisms to be applied to entries in the cache. Cache entries can be expired a certain number of seconds after creation, at a specific time of day each day, or on a specific date.|
||300||The configuration setting (either integer or dateTime) for the previous selection, "Expiration Type".|
||100||Maximum number of entries, cache keeps in memory. Upon reaching the max limit the entries are evicted using the LRU algorithm.|
||0||All entries larger than the configured setting size, in kilobytes, will be compressed before being cached.|
||false||An option that can be enabled or disabled. When enabled, an option is exposed that enables you to configure the size threshold above which cache entries will be compressed.|
||1024||All entries larger than the configured setting size, in kilobytes, will be compressed before being cached.|
||false||An option that can be enabled or disabled. When enabled, an option is exposed that enables you to configure the maximum size of data to be cached.|
||512 kilobytes||The size limit, in kilobytes, for cache entries. Data larger than the limit you set will not be cached.|