Skip to content

Cookies

The behavior of the page cache does not vary for most cookies. For sites that personalize content based on a cookie that is not listed below, the response will be cached and served to the next user regardless of whether they have that cookie with the same value or not.

A URL will be marked as PASS cache (the request and response will be considered uncacheable) if the request has one of the following cookies:

  • A WordPress comment cookie
  • A WordPress test cookie
  • A WordPress post password cookie
  • A WordPress authentication cookie
  • A WooCommerce session cookie
  • The VIP cache bypass cookie vip-go-cb (must have a value of exactly 1)
  • A PHP session cookie

A URL will be marked as uncacheable (hit-for-pass) for 10 seconds if:

  • it has a TTL less than or equal to 0 AND a response status code less than 400
  • OR it has a Set-Cookie header (set with setcookie() )
  • OR it has a Cache-Control header with a private value
  • OR it has a Vary header with a value of *.

Avoiding negative performance impact

Setting cookies on pages or endpoints can negatively affect the stability of a site, particularly if those routes are not exceptionally fast. Requests to URLs that set a cookie or bypass the cache will result in SQL queries on the origin server. This can have performance implications for a site, particularly during a high traffic event. A large volume of direct SQL queries can overload the primary database and lead to an increase in responses with a 503 HTTP status code.

To improve the performance of server-generated pages or URLs that bypass the cache due to cookie usage:

  • Optimize WordPress database queries to improve the performance of these pages when they bypass the cache.
  • Move user-level interactions to client-side using JavaScript and fast AJAX requests whenever possible.
  • Utilize Query Monitor and other tools, such as New Relic, to identify and analyze bottlenecks.
  • Use the object cache as much as possible to save data that may take significant time to query or generate, or that must be fetched remotely.
  • Avoid events that cause the cache to frequently expire, as doing so can cause a cache stampede.
  • Use the VIP Cache API to optimize caching.
  • Stagger the release of campaigns and cookie-related changes. Suddenly setting cookies for a large number of site visitors can cause an increase in requests to origin that may occur too quickly to be absorbed by autoscaling.

Last updated: February 29, 2024

Relevant to

  • WordPress