Customizing Page Cache Exclusions

By default, any POST request or URLs containing query string parameters bypass the page cache. Users who are logged into WordPress, or have items in their WooCommerce or Easy Digital Downloads carts will also bypass the page cache. In addition, SpinupWP excludes the following paths from being cached:

/wp-admin/
/wp-json/
/xmlrpc.php
/wp-.*.php
/feed/
index.php
sitemap(_index)?.xml
/cart/
/checkout/
/my-account/

Be aware that these default paths will cache nested paths. For example, /my-account/settings/ and /my-account/orders/ will be excluded from the page cache. While these default exclusions serve as a good starting point for most sites, you’re free to completely customize the cache exclusions.

Modifying Cache Exclusions

Because you will be editing Nginx config files that are owned by the root user, you will need to SSH to your server using a Sudo User.

Your server uses a global file located at /etc/nginx/global/fastcgi-cache.conf to control page caching exclusions. This file is symlinked into each site’s Nginx config, meaning all sites share the same cache exclusions. However, you may wish for each site to have slightly different exclusions. In this case you should remove the symlink from /etc/nginx/sites-available/{DOMAIN}/server/fastcgi-cache.conf and replace it with a copy of /etc/nginx/global/fastcgi-cache.conf.

The following section in the fastcgi-cache.conf file is responsible for excluding specific paths from the page cache:

# Don't cache URIs containing the following segments
if ($request_uri ~* "/wp-admin/|/wp-json/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|/cart/|/checkout/|/my-account/") {
    set $skip_cache 1;
}

The ~* indicates that the conditional is using a case-insensitive regular expression (regex) to match URIs. Anything within the "" will form the regular expression. If you’re not familiar with formatting regular expressions, a tool such as RegExr may be helpful.

You can add additional exclusions by appending the path to the regex with a prefix of |. For example, to exclude /members you would add |/members/, like so:

# Don't cache URIs containing the following segments
if ($request_uri ~* "/wp-admin/|/wp-json/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|/cart/|/checkout/|/my-account/|/members/") {
    set $skip_cache 1;
}

To verify that there are no issues with your config changes you should run:

sudo nginx -t

Remember to reload Nginx for the changes to take effect:

sudo service nginx reload

Page Cache Headers

When the page cache is enabled in SpinupWP all responses will have the Fastcgi-Cache header present. This header can have 1 of 3 values:

MISS – The page is not cached but will be on subsequent requests
HIT – The page is cached
BYPASS – The page is excluded from the page cache

You can use these values to help debug page caching issues.

Ready to give SpinupWP a try?

Not sure if SpinupWP is the right fit for you? Send us an email at sudo@spinupwp.com and we’ll give you our no-BS opinion.

Subscribe to get the latest news, updates and optimizations in performance and security.

Thanks for subscribing 👍

To receive awesome stuff, you'll need to head to your inbox and click on the verification link we sent you.
Make sure to check your "spam" folder or your "promotions" tab (if you have Gmail).
If you're still having trouble, then messages us at sudo@spinupwp.com.