---
title: RequestCacheKey
summary: 'An extension trait for Requests that adds methods for controlling cache keys. # Stability'
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/trait.RequestCacheKey/
---

**Kind:** Trait  
**Module:** [experimental](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/experimental/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#125

```rust
pub trait RequestCacheKey {
    // Required methods
    fn set_cache_key(&mut self, key: [u8; 32]);
    fn with_cache_key(self, key: [u8; 32]) -> Self;
    fn set_cache_key_fn(
        &mut self,
        f: impl Fn(&Request) -> [u8; 32] + Send + Sync + 'static,
    );
    fn with_cache_key_fn(
        self,
        f: impl Fn(&Request) -> [u8; 32] + Send + Sync + 'static,
    ) -> Self;
    fn set_cache_key_str(&mut self, key_str: impl AsRef<[u8]>);
    fn with_cache_key_str(self, key_str: impl AsRef<[u8]>) -> Self;
}
```

An extension trait for [`Request`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/)s that adds methods for controlling cache keys.
## Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

## Methods

### set_cache_key

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#128

```rust
fn set_cache_key(&mut self, key: [u8; 32])
```

See [`Request::set_cache_key()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-set_cache_key).
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `&mut Self`
- `key`: `[u8; 32]`

### set_cache_key_fn

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#134

```rust
fn set_cache_key_fn(&mut self, f: impl Fn(&Request) -> [u8; 32] + Send + Sync + 'static)
```

See [`Request::set_cache_key_fn()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#impl-RequestCacheKey).
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `&mut Self`
- `f`: `impl Fn(&Request) -> [u8; 32] + Send + Sync + 'static`

### set_cache_key_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#140

```rust
fn set_cache_key_str(&mut self, key_str: impl AsRef<[u8]>)
```

See [`Request::set_cache_key_str()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#impl-RequestCacheKey).
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `&mut Self`
- `key_str`: `impl AsRef<[u8]>`

### with_cache_key

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#131

```rust
fn with_cache_key(self, key: [u8; 32]) -> Self
```

See [`Request::with_cache_key()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-with_cache_key).
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `Self`
- `key`: `[u8; 32]`

**Returns**

`Self`

### with_cache_key_fn

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#137

```rust
fn with_cache_key_fn(self, f: impl Fn(&Request) -> [u8; 32] + Send + Sync + 'static) -> Self
```

See [`Request::with_cache_key_fn()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#impl-RequestCacheKey).
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `Self`
- `f`: `impl Fn(&Request) -> [u8; 32] + Send + Sync + 'static`

**Returns**

`Self`

### with_cache_key_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#143

```rust
fn with_cache_key_str(self, key_str: impl AsRef<[u8]>) -> Self
```

See [`Request::with_cache_key_str()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#impl-RequestCacheKey).
#### Stability

This is part of an experimental API that is subject to change or removal even in minor versions of
this crate.

**Parameters**

- `self`: `Self`
- `key_str`: `impl AsRef<[u8]>`

**Returns**

`Self`
