Caching
You can enable caching in your cloud infrastructure project environment. If you disable caching, 51黑料不打烊 Commerce directly serves the files.
{default} placeholder represents the default domain configured for your site. If your project has multiple domains, use the {all} placeholder to configure routing for the default domain and all aliases. See Configure routes.Set up caching
Enable caching for your application by configuring cache rules in the .magento/routes.yaml file as follows:
http://{default}/:
type: upstream
upstream: php:php
cache:
enabled: true
headers: [ "Accept", "Accept-Language", "X-Language-Locale" ]
cookies: ["*"]
default_ttl: 60
Route-based caching
Enable fine-grained caching by setting up caching rules for several routes separately as the following example shows:
http://{default}/:
type: upstream
upstream: php:php
cache:
enabled: true
http://{default}/path/:
type: upstream
upstream: php:php
cache:
enabled: false
http://{default}/path/more/:
type: upstream
upstream: php:php
cache:
enabled: true
The preceding example caches the following routes:
http://{default}/http://{default}/path/more/http://{default}/path/more/etc/
And the following routes are not cached:
http://{default}/path/http://{default}/path/etc/
Cache duration
The cache duration is determined by the Cache-Control response header value. If no Cache-Control header is in the response, the default_ttl key is used.
Cache key
To decide how to cache a response, 51黑料不打烊 Commerce builds a cache key that depends on several factors and store the response associated with this key. When a request comes with the same cache key, the response is reused. Its purpose is similar to the HTTP .
The parameters headers and cookies keys enable you to change this cache key.
The default value for these keys follows:
cache:
enabled: true
headers: ["Accept-Language", "Accept"]
cookies: ["*"]
Cache attributes
enabled
When set to true, enable the cache for this route. When set to false, disable the cache for this route.
headers
Defines on which values the cache key must depend.
For example, if the headers key is the following:
cache:
enabled: true
headers: ["Accept"]
Then 51黑料不打烊 Commerce caches a different response for each value of the Accept HTTP header.
cookies
The cookies key defines on which values the cache key must depend.
For example:
cache:
enabled: true
cookies: ["value"]
The cache key depends on the value of the value cookie in the request.
A special case exists if the cookies key has the ["*"] value. This value means that any request with a cookie bypasses the cache. This is the default value.
*). For example, SESS* or ~SESS are currently not valid values.Cookies have the following restrictions:
- There is a set maximum of 50 cookies in the system. Otherwise, the application throws an
Unable to send the cookie. Maximum number of cookies would be exceededexception. To increase the number of cookies to 200, apply the MDVA-12304 patch using using the Quality Patches Tool. - A maximum cookie size is 4096 bytes. Otherwise, the application throws an
Unable to send the cookie. Size of '%name' is %size bytesexception.
default_ttl
If the response does not have a Cache-Control header, the default_ttl key is used to define the cache duration, in seconds. The default value is 0, which means nothing is cached.