compute-starter-kit-rust-advanced-caching

Rust Starter Kit for Fastly Compute with advanced caching features

Platform:
Fastly Compute
Language:
Rust
Repo:
https://github.com/fastly/compute-starter-kit-rust-advanced-caching

Use this starter

Using the Fastly CLI, create a new project using this starter somewhere on your computer:

$ fastly compute init --from=https://github.com/fastly/compute-starter-kit-rust-advanced-caching

Or click the button below to create a GitHub repository, provision a Fastly service, and set up continuous deployment:

Deploy to Fastly

What's this?

As of version 0.11.0 of the Fastly Compute SDK for Rust, it is now possible to apply advanced caching techniques while accessing the Fastly readthrough cache.

  • Modifying a request as it is forwarded to a backend
  • Controlling cache behavior based on backend response
  • Manipulating the response body that is stored to the cache

This starter kit gives you a starting point for calling these extension points, enabling you to understand and customize powerful caching behavior with Fastly Compute.

[!NOTE] The advanced caching features whose uses are illustrated in this starter kit are not currently supported in Fastly's local development server. Attempting to run this starter kit in the local development server may result in the following error:

HTTP caching API is not enabled.

Understanding the code

Because advanced caching requirements vary significantly between applications, this starter kit is not designed to be deployed and run directly out of the box, unlike most Fastly Compute starter kits. Rather, it is a starting point for a Fastly Compute application code that shows how to set up the advanced caching features of the readthrough cache:

Since the code of this starter kit works with the Fastly readthrough cache, it expects a configured backend named "origin" that points to an origin server. For example, if the server is available at domain example.com, then you'll need to create a backend on your Compute service named "origin" with the destination host set to example.com and port 443. Also set Override Host to the same host value.

For details on advanced caching, see Customizing cache interaction with the backend in the developer documentation.

Next steps

Starters are a good way to bootstrap a project. For more specific use cases, and answers to common problems, try our library of code examples.