Azion `Purge` library
Learn how to use the `Purge` library to manage cache purging in your web applications.
The Purge library provides methods to interact with the Cache Purge API, allowing you to purge URLs, cache keys, and wildcard expressions from the cache. This client is configurable and supports both debug mode and environment variable-based configuration.
Go to Azion Libraries OverviewYou can interact with the API using a client or calling the methods directly from the library. When making direct calls, you can use the environment variables to configure the client without passing the token and debug parameters directly.
This is an example of how a .env file with your environment variables may look like:
| Variable | Description |
|---|---|
AZION_TOKEN | Your Azion API token. |
AZION_DEBUG | Enable debug mode (true/false). |
If you want to create a specific client for interacting with Purge, do it by calling the createClient method from the library:
The createClient method has the following parameters and return value:
Parameters:
| Parameter | Type | Description |
|---|---|---|
config | Partial<{ token: string; options?: OptionsParams }> | Configuration options for the Purge client. |
Returns:
| Return Type | Description |
|---|---|
AzionPurgeClient | An object with methods to interact with Purge. |
Usage
purgeURL
Purges a URL from the Cache.
Example:
Parameters:
| Parameter | Type | Description |
|---|---|---|
url | string[] | URL(s) to purge. |
options | AzionClientOptions (optional) | Client options including debug mode. |
Returns:
| Return Type | Description |
|---|---|
Promise<AzionPurgeResponse<AzionPurge>> | The purge response or error in case of failure. |
purgeCacheKey
Purges a cache key from the cache.
Example:
Parameters:
| Parameter | Type | Description |
|---|---|---|
cacheKey | string[] | Cache key(s) to purge. |
options | AzionClientOptions (optional) | Client options including debug mode. |
Returns:
| Return Type | Description |
|---|---|
Promise<AzionPurgeResponse<AzionPurge>> | The purge response or error in case of failure. |
purgeWildCard
Purges using a wildcard expression from the cache.
Example:
Parameters:
| Parameter | Type | Description |
|---|---|---|
wildcard | string[] | Wildcard expression(s) to purge. |
options | AzionClientOptions (optional) | Client options including debug mode. |
Returns:
| Return Type | Description |
|---|---|
Promise<AzionPurgeResponse<AzionPurge>> | The purge response or error in case of failure. |
Types
This section defines the various types and interfaces used in the Purge library.
ClientConfig
Configuration options for the Purge client.
| Parameter | Type | Description |
|---|---|---|
token | string (optional) | Your Azion API token. |
options | AzionClientOptions (optional) | Additional options for the client. |
PurgeClient
An object with methods to interact with Purge.
| Method | Parameters | Return Type |
|---|---|---|
purgeURL | urls: string[], options?: AzionClientOptions | Promise<AzionPurgeResponse<AzionPurge>> |
purgeCacheKey | cacheKeys: string[], options?: AzionClientOptions | Promise<AzionPurgeResponse<AzionPurge>> |
purgeWildCard | wildcards: string[], options?: AzionClientOptions | Promise<AzionPurgeResponse<AzionPurge>> |
Purge
The response object from a purge request.
| Property | Type | Description |
|---|---|---|
state | executed | ’pending’` |
items | string[] | The items that were purged. |