---
title: purge_with_opts
summary: Purge the entry associated with the given cache key with specific options.
url: https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/simple/fn.purge_with_opts/
---

**Kind:** Function  
**Module:** [simple](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/simple/)  
**Package:** compute-sdk-cpp 0.7.0

Purge the entry associated with the given cache key with specific options.

The [`PurgeOptions`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/simple/class.PurgeOptions/) argument determines the scope of the purge operation.

Note: Purged values may persist in cache for a short time (~150ms or less) after this function returns.

Example POP-scoped purge (default):

Example global-scoped purge:

_Overload 1 of 2_

```cpp
tl::expected<void, CacheError> fastly::cache::simple::purge_with_opts(std::span<const std::uint8_t> key, const PurgeOptions &opts)
```

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/simple.h#L326

Purge the entry associated with the given cache key with specific options.

The [`PurgeOptions`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/simple/class.PurgeOptions/) argument determines the scope of the purge operation.

Note: Purged values may persist in cache for a short time (~150ms or less) after this function returns.

Example POP-scoped purge (default):

Example global-scoped purge:

**Parameters**

- `key`: `std::span<const std::uint8_t>`
- `opts`: `const PurgeOptions &`

**Returns**

`tl::expected<void, CacheError>`

```cpp
std::vector<std::uint8_t> key_bytes = {0x01, 0x02, 0x03};
purge_with_opts(key_bytes, PurgeOptions::pop_scope());
// Equivalent to just: purge(key_bytes);
```

```cpp
std::vector<std::uint8_t> key_bytes = {0x01, 0x02, 0x03};
purge_with_opts(key_bytes, PurgeOptions::global_scope());
```

_Overload 2 of 2_

```cpp
tl::expected<void, CacheError> fastly::cache::simple::purge_with_opts(std::string_view key, const PurgeOptions &opts)
```

**Source:** https://github.com/fastly/compute-sdk-cpp/blob/ff911e47be2f319e83a9cde960d2c3c5db534280/include/fastly/cache/simple.h#L348

Purge the entry associated with the given cache key with specific options.

The [`PurgeOptions`](https://www.fastly.com/documentation/reference/compute/sdks/cpp/fastly/cache/simple/class.PurgeOptions/) argument determines the scope of the purge operation.

Note: Purged values may persist in cache for a short time (~150ms or less) after this function returns.

Example POP-scoped purge (default):

Example global-scoped purge:

**Parameters**

- `key`: `std::string_view`
- `opts`: `const PurgeOptions &`

**Returns**

`tl::expected<void, CacheError>`

```cpp
purge_with_opts("my_key", PurgeOptions::pop_scope());
// Equivalent to just: purge("my_key");
```

```cpp
purge_with_opts("my_key", PurgeOptions::global_scope());
```
