-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cache] Adds section for cache interaction with other products (#17590)
* Adds section for cache interaction with other products * Update src/content/docs/cache/interaction-cloudflare-products/r2.mdx Co-authored-by: Jun Lee <junlee@cloudflare.com> * Removes note --------- Co-authored-by: Jun Lee <junlee@cloudflare.com>
- Loading branch information
1 parent
dfccbb3
commit 0b2f46e
Showing
8 changed files
with
121 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/content/docs/cache/interaction-cloudflare-products/index.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
pcx_content_type: navigation | ||
title: Interaction with Cloudflare products | ||
sidebar: | ||
order: 11 | ||
group: | ||
hideIndex: true | ||
|
||
--- | ||
|
||
import { DirectoryListing } from "~/components" | ||
|
||
Review the following topics to learn more about how Cache interacts with other Cloudflare products. | ||
|
||
<DirectoryListing /> |
25 changes: 25 additions & 0 deletions
25
src/content/docs/cache/interaction-cloudflare-products/r2.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
pcx_content_type: how-to | ||
title: Enable cache in an R2 bucket | ||
sidebar: | ||
order: 2 | ||
head: | ||
- tag: title | ||
content: Enable cache in an R2 bucket | ||
|
||
--- | ||
|
||
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: | ||
|
||
1. Go to **R2** and select your bucket. | ||
2. On the bucket page, select **Settings**. | ||
3. Under **Public access** > **Custom Domains**, select **Connect Domain**. | ||
4. Enter the domain name you want to connect to and select **Continue**. | ||
5. Review the new record that will be added to the DNS table and select **Connect Domain**. | ||
|
||
This will generate a publicly available CNAME in the format `[name].domain.com`. | ||
|
||
## Additional considerations | ||
|
||
- 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. | ||
- Be aware of the [cacheable size limits](/cache/concepts/default-cache-behavior/#cacheable-size-limits) for files. |
35 changes: 35 additions & 0 deletions
35
src/content/docs/cache/interaction-cloudflare-products/waf-snippets.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
pcx_content_type: how-to | ||
title: Control cache access with WAF and Snippets | ||
sidebar: | ||
order: 3 | ||
head: | ||
- tag: title | ||
content: Control cache access with WAF and Snippets | ||
|
||
--- | ||
|
||
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. | ||
|
||
The following diagram illustrates the flow of a user's request through WAF, Cache, and R2. | ||
|
||
```mermaid | ||
flowchart LR | ||
accTitle: Connections with Cloudflare | ||
A[User's request] --> B[WAF] --> C[Cache] --> D[R2] | ||
``` | ||
|
||
<br/> | ||
|
||
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. | ||
|
||
## Presigned URLs | ||
|
||
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. | ||
|
||
For optimal performance, we recommend separating the creation and validation processes as follows: | ||
|
||
- [Snippets](/rules/snippets/examples/signing-requests/) for HMAC creation | ||
- [Rules](/ruleset-engine/rules-language/functions/#hmac-validation) for HMAC validation | ||
|
||
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. |
43 changes: 43 additions & 0 deletions
43
src/content/docs/cache/interaction-cloudflare-products/workers.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
pcx_content_type: how-to | ||
title: Customize cache behavior with Workers | ||
sidebar: | ||
order: 1 | ||
head: | ||
- tag: title | ||
content: Customize cache behavior with Workers | ||
|
||
--- | ||
|
||
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. | ||
|
||
The diagram below illustrates a common interaction flow between Workers and Cache. | ||
|
||
![Workers and cache flow example flow diagram.](~/assets/images/cache/workers-cache-flow.png) | ||
|
||
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. | ||
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. | ||
|
||
Here are a few examples of how Workers can be used to customize cache behavior: | ||
|
||
- **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. | ||
|
||
- **Signed URLs**: Generate URLs that are valid for a specific duration (for example, minutes, hours, days) to control access and enhance security. | ||
|
||
- **Personalized Response**: Deliver personalized content based on user data while leveraging cached resources to reduce the load on the origin. | ||
|
||
- **Reduce Latency**: Serve content from a location close to the user, decreasing load times and improving the user experience. | ||
|
||
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. | ||
|
||
:::note | ||
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. | ||
::: | ||
|
||
## Cache features in Workers | ||
|
||
- **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/). | ||
|
||
- **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/). | ||
|
||
To understand more about how Cache and Workers interact refer to [Cache in Workers](/workers/reference/how-the-cache-works/). |