OCAPI Caching 23.1
As a REST API based on HTTP, the Open Commerce API enables developers to build client application caches or to leverage Proxy caches. The API delivers standard HTTP cache header information.
In Business Manager, you can configure maximum cache times (or max ages) for some Open Commerce API resources. At the moment, you can only configure the cache settings for the Shop API.
Site Page Caching must be enabled in Business Manager for caching functionality.
The max age determines how long (in seconds) a response document remains in the cache. At runtime, the configured max age is used to calculate a value that is added to the cache control header of the HTTP response. For example, suppose that you configure a max age of 900 seconds for the categories resource. After an initial GET request, the value included in the HTTP header would be 900. If a second GET request for the same document arrived 120 seconds later, the HTTP header value would be 780.
Response cache headers are only delivered for GET and HEAD requests in the Shop API for the
Configure cache times per resource in the Open Commerce API settings. The integer property
cache_time defines the cache time in seconds. If you don't specify a cache time, the default is 60 seconds. The minimum configurable cache time is 0 seconds, and the maximum is 86,400 seconds (24 hours).
Following is a sample cache time configuration:
The API returns the cache time as the
*Cache-Control: max-age* header, as in the following examples:
Example 1: Request product availability information:
Example 2: Request product price information:
Example 3: Request product availability and price information using the expand parameter:
For a single request using the expand parameter, the Open Commerce API populates the Cache-Control header with the lowest caching time of the requested resources.
Query parameters are part of the key of web caches like proxy or browser caches. OCAPI self-generated URLs always have the query parameters sorted alphabetically. This deterministic sorting order ensures a better cache hit rate.
To ensure better cache hit rates, improving performance, always build OCAPI URLs in client applications with the query parameters in alphabetic sorting order.
The Meta API also has caching enabled. The default cache time for the resources is 1 day, and can’t be configured. To clear the instance cache for Meta API documents, you have to invalidate the Business Manager page cache.