20.11.2026

How to set up Cache Rules without sharing personal data

How to set up Cache Rules for public files and protect personalised responses. A procedure for exceptions, TTL, cache keys and tests with different users.

Theo Marek

Theo Marek

Cloudflare Solutions Engineer at Integrity. Deploys DDoS protection, WAF and Zero Trust for companies in Czechia and Slovakia.

Cache Rules determine which responses the distributed cache may store and how long it may use them. A safe design starts by separating public files from responses that depend on a login. Only then does it make sense to adjust storage times or cache keys.

The same address can show public content to an anonymous visitor and their own account to a logged-in user. Caching such an address across the board requires different rules than storing a shared image. For the first deployment, therefore, pick clearly defined static content and exclude personalised responses from the cache.

  • Only content intended for all its recipients belongs in a shared cache
  • Assess logins, cookies and headers together with how the application behaves
  • Exception rules must hold up even where they overlap with other rules
  • Verify behaviour with different users, not just by repeating the same request

1. Divide responses by who they belong to

First, map the content the application serves. Separate shared images, styles and scripts from accounts, baskets or exports. For each group, determine whether the response changes depending on the user, their permissions or other inputs.

Neither a directory name nor a file extension can replace this decision. An application can generate a tailored response even at a seemingly static address. Assess the actual content of the response and the way the server assembles it.

In its default behaviour, Cloudflare derives whether static files are eligible for caching from their extension. It does not cache HTML and JSON by default. The details are in the overview of default cache behaviour, which is a good starting point before you make your own changes.

Create a simple table for the deployment plan. It does not need to list every address separately, but each group must share the same rules. Leave disputed cases outside the shared cache for now.

Response groupRecommended default approach
Public images, styles and scriptsConsider caching once you have verified they do not differ between users
Customer account and ordersExplicitly bypass the shared cache
Basket and checkoutExplicitly bypass the shared cache
Export created for a specific userKeep outside the shared cache
Response with unclear personalisation conditionsVerify the application's behaviour first

For each group, record the application owner and the expected way of updating. This helps when deciding how long stored content stays valid. If the owner cannot say who a response belongs to, do not extend caching yet.

Build the overview from responses, not only from pages visible in the browser. A single page can load shared images and, at the same time, personal data through other requests. These groups need different handling, even though the user sees them as a single screen.

Also include administration and supporting interfaces. In a first inventory it is easy to stop at the main customer journey. The scope of the rules, however, must match all the traffic of the host it covers.

2. Allow narrowly defined static content first

Create the first rule for a specific host and a verified group of public files. Choose conditions that do not touch the customer interface or other applications on the same domain. Simply including everything under one domain is too broad for a pilot like this.

The Cache Rules documentation sets out the conditions and cache settings. For these rules to apply, traffic for the relevant DNS record must be proxied. For a record that is not proxied, the rule does not control traffic in this way.

For the selected group, set cache eligibility and keep respecting the origin server's headers. For a conservative start, choose the option that bypasses the cache when the Cache-Control header is missing. Do not rely on whatever default a response happens to have.

Then check that the application actually sends the header. Check both the normal response and an error state at the same address. A redirect, a missing file or a server error may need different handling from a successfully loaded image.

It is useful to keep public static content separate during application development as well. For files with a version in their name, an update can be tied to a new address. If you replace content under the same address, the release process must account for its previously stored version.

Explain the chosen approach to the team that publishes the website. A developer needs to know whether to change the file name, adjust the validity period or trigger a cache purge. This information belongs in the normal release process, not only in the infrastructure settings.

Extend the pilot group by group, wherever you can confirm the content is of the same nature. Every new condition should have its own test examples. Include in the list the addresses the rule must not apply to.

When writing conditions, pay attention to path boundaries and the exact host name. Decide whether you want to cover a single application, all its subdirectories or other subdomains as well. Write the rule description so that an administrator who did not create it can understand the intent.

Before approval, have a second team member compare the description with the actual expression. Check that the intended scope matches the selected test addresses. This check should catch a mistake in a condition before you start watching operational metrics.

3. Exclude personalised traffic explicitly

For customer accounts, baskets and other private sections, create rules with the Bypass cache setting. Define them according to the actual architecture of the application. A separate path only helps if personalised content does not also appear outside it.

If the application uses a session cookie, add a matching condition based on its real name. The mechanism is shown in the example of bypassing the cache when a cookie is present. The sample name from the documentation, however, is no substitute for knowing how login works on your website.

Go through the list of cookies with the development team. Tell login apart from analytics, cookie consent or other preferences. Bypassing the cache for any cookie may be unnecessarily broad, while a single selected cookie may not cover every way of logging in.

Review authenticated requests with the Authorization header in the same way. Do not treat its presence as a universal guarantee that the response cannot be stored. The current Origin Cache Control rules describe how this depends on cache settings and response headers.

Do not build protection on the Set-Cookie header alone. With certain combinations of eligibility and a forced TTL, this header can be removed and the response stored. The exact combinations are described in the primary cache behaviour documentation.

Finally, check for overlapping rules. If several rules with the same setting match, the last matching value decides. Verify the order of Cache Rules for your actual set of rules, not only for the newly added exception.

Place the exception so that a later rule allowing caching does not override it. At the same time, restrict the allowing rule through its own conditions. The result is a clearer configuration that can be changed more safely without relying on a single order of entries.

When testing logout, check which cookies the application actually removes. Also verify switching between different accounts in one browser. Define the expected result by the user's identity and the content of the response, not just by the presence of a single header.

4. Distinguish the shared cache from the browser cache

Edge TTL sets how long content stays valid in the distributed cache. Browser TTL applies to the browser cache. Design each value according to how the content changes and how it can be updated.

A longer validity period is not automatically better. For a public file with a version in its name, you can choose a different mode than for a document replaced under the same address. The decision should follow from the publishing process and the acceptable age of the content.

The Cache-Control header also determines who may store a response. The meaning of its basic directives is summarised in the cache control documentation. When you use them, check that your own rule does not override them.

DirectiveWhat it means for the design
privateThe response is not intended for a shared cache
no-storeThe response should not be stored in caches
no-cacheRevalidation with the origin server is required before reuse

Pay particular attention to the difference between no-cache and no-store. The first does not, on its own, forbid storage. For private content, choose headers according to the behaviour you need and back them up with matching rules.

Do not force Cache-Control to be ignored across the whole application. Such a step can override decisions made by the server, which knows the context of the response. If you have a reason to override it for a specific public group, document it and test it separately.

Error responses need their own consideration too. An error stored for too long can persist even after its cause has been fixed on the server. Include settings by status code and the procedure for restoring normal operation in your review.

5. Verify the cache key and the separation of users

The cache key determines which stored item a request belongs to. Simplifying it can merge requests that the application handles differently. Before changing it, you must know which inputs actually change the response.

The default key also includes query parameters. If you start ignoring them, you may merge different variants of content. Justify leaving out a parameter by the application's behaviour, not just by the wish to increase the number of cache hits.

A parameter marking a campaign may be irrelevant to the content, but verify it. A parameter that selects the language, a product variant or a file version may mean something else. These examples are not universal rules for specific parameter names.

Key customisation and the available options are described in the current primary documentation on cache keys. Do not assume that every plan offers all customisation options. For a first safe deployment, the default key and a narrower caching scope may be the better choice.

Prepare separate sessions for an anonymous visitor and for different test users. Repeat requests in a different order and compare their content. Also verify what happens after logging in, logging out and a change of permissions.

In every test, check both the response and the cache diagnostics. A page that loads successfully does not yet mean the right person got the right data. Likewise, a single cache hit does not prove the whole rule is safe.

Use test accounts and recognisable test data. You do not need sensitive production records for verification. The result must clearly show that a private response did not carry over between sessions.

Separate the test of the origin application from the test of the path through the distributed cache. First confirm the correct content and headers of the application's response. Then compare the result after the rules are applied, so that you know in which part any deviation arose.

For a reproducible problem, keep the order of requests and the test identity used. Without this information, the result may differ when repeated. Do not put real values of access tokens or session cookies in the record.

6. Prepare the release and a way back

Before deployment, keep a copy of the previous rules, their order and the headers of the tested responses. Write down the reason for the change and the expected behaviour. Run the same test set after the change and in the event of a rollback.

If content that does not belong there has got into the cache, adjusting the rule alone is not a complete fix. Also include purging the affected items and checking how they load afterwards. With a custom key, take its variants into account when choosing how to purge.

Review the settings whenever login, path structure or the publishing process changes. A new cookie or moving an account to a different address can change the original assumptions. Tie responsibility for reviewing the cache to responsibility for the application.

Should everything that does not require login be cached?

First check that the response does not depend on other properties of the visitor or the request. Even anonymous traffic can receive different variants of content. For sharing, it must be clear which requests may receive the same response.

Is the highest cache hit ratio the right goal?

You also have to assess whether the content is correct and up to date. Higher cache usage has no value if a user receives someone else's response or one that is unsuitably old. Assess operational metrics alongside functional tests of the application.

Start with one verified group of public files and clear exceptions. For a consultation with Integrity, prepare a map of responses, logins and the rules in use. On that basis you can decide which other parts of the website are suitable for caching.

Sources