Features Pricing Reviews FAQ
Get Plugin

Custom Cache Rules (Pro)

5 min read

Apply cache rules to many pages at once. xSpeed Cache Pro lets you bypass the cache or set a custom cache lifetime based on a URL pattern, post type, category, tag, or author.

What this does

The free version of xSpeed Cache lets you control caching for a single post from its editor. Custom Cache Rules adds rules that match a pattern across many posts at the same time.

Each rule has two parts: a condition (what to match) and an action (what to do when it matches). For example, a rule can say “every post of type product should bypass the cache,” or “every post in a given category should expire after 1 hour.”

Rules are checked in order, from top to bottom. The first rule that matches a request wins, and no later rules are applied to it.

Why use it

Setting caching post by post does not scale. If you want all of your products, all posts in a category, or every URL under a path to behave the same way, a single rule covers them all. It also keeps personalized or fast-changing pages out of the cache without editing each one.

Requirements

  • xSpeed Cache Pro must be installed and active.
  • Page caching should be enabled, since these rules control how the page cache treats matching requests.

Conditions you can match on

A rule matches on exactly one of these conditions:

ConditionWhat it matchesValue you provide
URL patternThe request URLA glob pattern, e.g. /cart/* or *.pdf
Post typeThe post’s typeA post type name, e.g. product
CategoryThe post’s categoryA category ID number
TagThe post’s tagA tag ID number
AuthorThe post’s authorA user ID number

A few details that matter when you set the value:

  • URL pattern uses glob matching. * matches any run of characters and ? matches a single character. The match starts at the beginning of the URL, so /cart matches /cart, /cart/items, and anything else starting with /cart. It does not match /shop/cart.
  • Category and Tag take the term’s numeric ID, not its name or slug.
  • Author takes the user’s numeric ID.
  • Post type, Category, Tag, and Author only apply to requests that resolve to a single post. The URL pattern condition works on any request URL.

Actions you can take

A rule does one of two things when it matches:

ActionWhat it does
Bypass cacheThe matching page is never served from cache and is not cached
Expiry (hours)The matching page uses the number of hours you set as its cache lifetime

For the expiry action you also set the number of hours. A value of zero or less is ignored, so a custom expiry must be at least 1 hour.

How to add a rule

  1. Open the xSpeed Cache dashboard and go to the Custom Cache Rules panel.
  2. Add a new rule.
  3. Choose a condition and enter its value (a URL pattern, post type name, category ID, tag ID, or author ID).
  4. Choose an action — bypass the cache, or set a custom expiry in hours.
  5. If you chose expiry, enter the number of hours.
  6. Optionally add a label so you remember what the rule is for.
  7. Save your rules.

Tip: Order matters. Because the first matching rule wins, put your more specific rules above broader ones.

How rules work with free per-post settings

Custom Cache Rules build on the per-post controls in free xSpeed Cache; they do not replace them.

  • If a post’s own settings already say to skip the cache, that decision stands. A rule cannot un-skip a page that free has already chosen to skip.
  • If a post already has its own custom expiry set in the editor, that per-post value is respected and the rules do not override it.

In short, per-post settings take priority, and Custom Cache Rules fill in the behavior for everything they do not cover.

Best practices

  • Use bypass cache for pages that must always be fresh or are personalized, such as cart, checkout, and account pages.
  • Use expiry (hours) for content that changes on a predictable schedule, such as a category of fast-moving posts.
  • Add a clear label to each rule so the list stays readable as it grows.
  • Keep specific rules above general ones, since the first match wins.

Troubleshooting

My URL rule is not matching the pages I expected. The pattern matches from the start of the URL. To match a path anywhere, lead with * (for example */cart/*). Remember that /cart already matches everything starting with /cart.

My category or tag rule does nothing. These conditions need the term’s numeric ID, and they only apply to single-post requests. Confirm you entered the ID, not the name or slug.

A page I expected to bypass is still cached. Check rule order. An earlier rule that matched first may have applied a different action. Move the bypass rule higher if needed.

FAQ

Can one rule match on more than one condition at a time? No. Each rule matches on a single condition. Use multiple rules to cover multiple cases.

What happens if two rules match the same page? The first matching rule in the list wins. Later matches are ignored for that request.

Does a custom expiry of 0 hours disable caching for the page? No. An expiry of zero or less is ignored. Use the bypass cache action if you want a page to never be cached.

  • Page Cache
  • Cache Exclusions
  • Cache Lifetime