Skip to content

Commit 0b2f46e

Browse files
[Cache] Adds section for cache interaction with other products (cloudflare#17590)
* Adds section for cache interaction with other products * Update src/content/docs/cache/interaction-cloudflare-products/r2.mdx Co-authored-by: Jun Lee <[email protected]> * Removes note --------- Co-authored-by: Jun Lee <[email protected]>
1 parent dfccbb3 commit 0b2f46e

File tree

8 files changed

+121
-19
lines changed

8 files changed

+121
-19
lines changed

public/_redirects

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@
211211
/cache/about/ /cache/concepts/ 301
212212
/cache/concepts/enable-http2-to-origin/ /speed/optimization/protocol/http2-to-origin/ 301
213213
/cache/how-to/enable-http2-to-origin/ /speed/optimization/protocol/http2-to-origin/ 301
214-
/cache/how-to/interact-with-workers/ /cache/concepts/interact-with-workers/ 301
214+
/cache/how-to/interact-with-workers/ /cache/interaction-cloudflare-products/workers/ 301
215+
/cache/concepts/interact-with-workers/ /cache/interaction-cloudflare-products/workers/ 301
215216
/cache/best-practices/cache-behavior/ /cache/concepts/cache-behavior/ 301
216217
/cache/best-practices/customize-cache/ /cache/concepts/customize-cache/ 301
217218
/cache/best-practices/ /cache/concepts/ 301
807 KB
Loading

src/content/docs/cache/concepts/interact-with-workers.mdx

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/content/docs/cache/concepts/retention-vs-freshness.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ The time window that an object should be considered safe for a cache to use is d
1616

1717
* Include [Origin Cache Control](/cache/concepts/cache-control/) or [CDN Cache Control](/cache/concepts/cache-control/) directives, like `max-age` or `s-maxage`, in the origin cache-control response header.
1818

19-
* Use [Cache Rules](/cache/how-to/cache-rules/) or [Workers](/cache/concepts/interact-with-workers/).
19+
* Use [Cache Rules](/cache/how-to/cache-rules/) or [Workers](/cache/interaction-cloudflare-products/workers/).
2020

2121
If an object in cache is no longer fresh and Cloudflare receives a request for it, we ask the origin to revalidate the object we have in cache. The Origin can then either send a new version of the object which will replace the old in cache, or tell us the object we have is valid and to refresh its TTL. This revalidation will happen any time an object’s retention period is greater than its freshness period.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
pcx_content_type: navigation
3+
title: Interaction with Cloudflare products
4+
sidebar:
5+
order: 11
6+
group:
7+
hideIndex: true
8+
9+
---
10+
11+
import { DirectoryListing } from "~/components"
12+
13+
Review the following topics to learn more about how Cache interacts with other Cloudflare products.
14+
15+
<DirectoryListing />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Enable cache in an R2 bucket
4+
sidebar:
5+
order: 2
6+
head:
7+
- tag: title
8+
content: Enable cache in an R2 bucket
9+
10+
---
11+
12+
To enable edge caching for a [Cloudflare R2](/r2/) bucket, make sure your bucket is public and accessible by the Cache. This can be done by creating a [Custom Domain](/r2/buckets/public-buckets/#custom-domains). Follow these steps to set up a Custom Domain for your bucket:
13+
14+
1. Go to **R2** and select your bucket.
15+
2. On the bucket page, select **Settings**.
16+
3. Under **Public access** > **Custom Domains**, select **Connect Domain**.
17+
4. Enter the domain name you want to connect to and select **Continue**.
18+
5. Review the new record that will be added to the DNS table and select **Connect Domain**.
19+
20+
This will generate a publicly available CNAME in the format `[name].domain.com`.
21+
22+
## Additional considerations
23+
24+
- Apply access controls to your newly public bucket. Refer to [Control cache access with WAF and Snippets](/cache/interaction-cloudflare-products/waf-snippets/) for more information.
25+
- Be aware of the [cacheable size limits](/cache/concepts/default-cache-behavior/#cacheable-size-limits) for files.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Control cache access with WAF and Snippets
4+
sidebar:
5+
order: 3
6+
head:
7+
- tag: title
8+
content: Control cache access with WAF and Snippets
9+
10+
---
11+
12+
To limit access to the public bucket created for caching content, you can use Cloudflare's [WAF](/waf/custom-rules/use-cases/configure-token-authentication/). The WAF provides an additional security layer to filter requests and ensure that only authorized traffic reaches your bucket.
13+
14+
The following diagram illustrates the flow of a user's request through WAF, Cache, and R2.
15+
16+
```mermaid
17+
flowchart LR
18+
accTitle: Connections with Cloudflare
19+
A[User's request] --> B[WAF] --> C[Cache] --> D[R2]
20+
```
21+
22+
<br/>
23+
24+
The WAF product uses token authentication to either sign or authenticate a request. You can then use this in either Workers or Snippets to control access.
25+
26+
## Presigned URLs
27+
28+
You can presign URLs similar to [S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html), enabling you to share direct access to your content with a with an associated timeout. This approach can be implemented using a combination of Snippets, Rules, or Cloudflare Workers.
29+
30+
For optimal performance, we recommend separating the creation and validation processes as follows:
31+
32+
- [Snippets](/rules/snippets/examples/signing-requests/) for HMAC creation
33+
- [Rules](/ruleset-engine/rules-language/functions/#hmac-validation) for HMAC validation
34+
35+
In the Workers documentation, in the section [Signing requests](/workers/examples/signing-requests/), you can also find an example of how to verify a signed request using the HMAC.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Customize cache behavior with Workers
4+
sidebar:
5+
order: 1
6+
head:
7+
- tag: title
8+
content: Customize cache behavior with Workers
9+
10+
---
11+
12+
You can use [Workers](/workers/) to customize cache behavior on Cloudflare's CDN. Cloudflare Workers provide flexibility in handling assets and responses by running both before and after the cache. A Worker can be configured to run before a request reaches the cache, allowing for modifications to the request, and it can also be used to modify assets once they are returned from the cache.
13+
14+
The diagram below illustrates a common interaction flow between Workers and Cache.
15+
16+
![Workers and cache flow example flow diagram.](~/assets/images/cache/workers-cache-flow.png)
17+
18+
1. A User (a) Requests a URI, and this request is directed to a Worker. The Worker can then interact with the request, either requesting the content further upstream using (b) fetch() or sending a (f) Response back to the User.
19+
2. If the content is cached, the Cache will send a (e) Response back to the Worker which can now interact with the response before sending a (f) Response back to the user.
20+
21+
Here are a few examples of how Workers can be used to customize cache behavior:
22+
23+
- **Modify Response**: Adjust or enhance content after it is retrieved from the cache, ensuring that responses are up-to-date or tailored to specific needs.
24+
25+
- **Signed URLs**: Generate URLs that are valid for a specific duration (for example, minutes, hours, days) to control access and enhance security.
26+
27+
- **Personalized Response**: Deliver personalized content based on user data while leveraging cached resources to reduce the load on the origin.
28+
29+
- **Reduce Latency**: Serve content from a location close to the user, decreasing load times and improving the user experience.
30+
31+
You can also use [Snippets](/rules/snippets/) as a low-cost alternative for simple modifications and logic, bypassing the need for full Worker scripts. These lightweight scripts enable quick adjustments and optimizations, offering an efficient way to enhance your Cloudflare setup without the complexity and overhead of more extensive code deployments.
32+
33+
:::note
34+
When using Workers and [Orange-to-Orange (O2O)](/cloudflare-for-platforms/cloudflare-for-saas/saas-customers/how-it-works/), some caveats and limitations may apply.
35+
:::
36+
37+
## Cache features in Workers
38+
39+
- **fetch()**: Allows interaction with Cloudflare's Cache and Tiered Cache, providing control over how requests are handled. To optimize caching behavior, you can set TTLs, define custom cache keys, and configure cache headers directly within a fetch request. For more details on these configurations, refer to [Cache using fetch](/workers/examples/cache-using-fetch/).
40+
41+
- **Cache API**: Enables storing and retrieving responses from Cloudflare's cache, limited to the cache in the local data center and excluding content stored in the Tiered Cache. To use the Cache API to store responses in Cloudflare's cache, refer to [Using the Cache API](/workers/examples/cache-api/).
42+
43+
To understand more about how Cache and Workers interact refer to [Cache in Workers](/workers/reference/how-the-cache-works/).

0 commit comments

Comments
 (0)