cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/cache/cache.ts
127lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. |
| 2 | |
| 3 | import * as Core from 'cloudflare/core'; |
| 4 | import { APIResource } from 'cloudflare/resource'; |
| 5 | import * as CacheAPI from 'cloudflare/resources/cache/cache'; |
| 6 | import * as CacheReserveAPI from 'cloudflare/resources/cache/cache-reserve'; |
| 7 | import * as RegionalTieredCacheAPI from 'cloudflare/resources/cache/regional-tiered-cache'; |
| 8 | import * as TieredCacheSmartTopologyAPI from 'cloudflare/resources/cache/tiered-cache-smart-topology'; |
| 9 | import * as VariantsAPI from 'cloudflare/resources/cache/variants'; |
| 10 | |
| 11 | export class Cache extends APIResource { |
| 12 | cacheReserve: CacheReserveAPI.CacheReserve = new CacheReserveAPI.CacheReserve(this._client); |
| 13 | tieredCacheSmartTopology: TieredCacheSmartTopologyAPI.TieredCacheSmartTopology = |
| 14 | new TieredCacheSmartTopologyAPI.TieredCacheSmartTopology(this._client); |
| 15 | variants: VariantsAPI.Variants = new VariantsAPI.Variants(this._client); |
| 16 | regionalTieredCache: RegionalTieredCacheAPI.RegionalTieredCache = |
| 17 | new RegionalTieredCacheAPI.RegionalTieredCache(this._client); |
| 18 | |
| 19 | /** |
| 20 | * ### Purge All Cached Content |
| 21 | * |
| 22 | * Removes ALL files from Cloudflare's cache. All tiers can purge everything. |
| 23 | * |
| 24 | * ### Purge Cached Content by URL |
| 25 | * |
| 26 | * Granularly removes one or more files from Cloudflare's cache by specifying URLs. |
| 27 | * All tiers can purge by URL. |
| 28 | * |
| 29 | * To purge files with custom cache keys, include the headers used to compute the |
| 30 | * cache key as in the example. If you have a device type or geo in your cache key, |
| 31 | * you will need to include the CF-Device-Type or CF-IPCountry headers. If you have |
| 32 | * lang in your cache key, you will need to include the Accept-Language header. |
| 33 | * |
| 34 | * **NB:** When including the Origin header, be sure to include the **scheme** and |
| 35 | * **hostname**. The port number can be omitted if it is the default port (80 for |
| 36 | * http, 443 for https), but must be included otherwise. |
| 37 | * |
| 38 | * ### Purge Cached Content by Tag, Host or Prefix |
| 39 | * |
| 40 | * Granularly removes one or more files from Cloudflare's cache either by |
| 41 | * specifying the host, the associated Cache-Tag, or a Prefix. Only Enterprise |
| 42 | * customers are permitted to purge by Tag, Host or Prefix. |
| 43 | * |
| 44 | * **NB:** Cache-Tag, host, and prefix purging each have a rate limit of 30,000 |
| 45 | * purge API calls in every 24 hour period. You may purge up to 30 tags, hosts, or |
| 46 | * prefixes in one API call. This rate limit can be raised for customers who need |
| 47 | * to purge at higher volume. |
| 48 | */ |
| 49 | purge( |
| 50 | zoneId: string, |
| 51 | body: CachePurgeParams, |
| 52 | options?: Core.RequestOptions, |
| 53 | ): Core.APIPromise<CachePurgeResponse | null> { |
| 54 | return ( |
| 55 | this._client.post(`/zones/${zoneId}/purge_cache`, { body, ...options }) as Core.APIPromise<{ |
| 56 | result: CachePurgeResponse | null; |
| 57 | }> |
| 58 | )._thenUnwrap((obj) => obj.result); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | export interface CachePurgeResponse { |
| 63 | /** |
| 64 | * Identifier |
| 65 | */ |
| 66 | id: string; |
| 67 | } |
| 68 | |
| 69 | export type CachePurgeParams = |
| 70 | | CachePurgeParams.CachePurgeTags |
| 71 | | CachePurgeParams.CachePurgeHosts |
| 72 | | CachePurgeParams.CachePurgePrefixes |
| 73 | | CachePurgeParams.CachePurgeEverything |
| 74 | | CachePurgeParams.CachePurgeFiles; |
| 75 | |
| 76 | export namespace CachePurgeParams { |
| 77 | export interface CachePurgeTags { |
| 78 | tags?: Array<string>; |
| 79 | } |
| 80 | |
| 81 | export interface CachePurgeHosts { |
| 82 | hosts?: Array<string>; |
| 83 | } |
| 84 | |
| 85 | export interface CachePurgePrefixes { |
| 86 | prefixes?: Array<string>; |
| 87 | } |
| 88 | |
| 89 | export interface CachePurgeEverything { |
| 90 | purge_everything?: boolean; |
| 91 | } |
| 92 | |
| 93 | export interface CachePurgeFiles { |
| 94 | files?: Array<string | CachePurgeFiles.CachePurgeURLAndHeaders>; |
| 95 | } |
| 96 | |
| 97 | export namespace CachePurgeFiles { |
| 98 | export interface CachePurgeURLAndHeaders { |
| 99 | headers?: unknown; |
| 100 | |
| 101 | url?: string; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | export namespace Cache { |
| 107 | export import CachePurgeResponse = CacheAPI.CachePurgeResponse; |
| 108 | export import CachePurgeParams = CacheAPI.CachePurgeParams; |
| 109 | export import CacheReserve = CacheReserveAPI.CacheReserve; |
| 110 | export import CacheReserveListResponse = CacheReserveAPI.CacheReserveListResponse; |
| 111 | export import CacheReserveEditResponse = CacheReserveAPI.CacheReserveEditResponse; |
| 112 | export import CacheReserveEditParams = CacheReserveAPI.CacheReserveEditParams; |
| 113 | export import TieredCacheSmartTopology = TieredCacheSmartTopologyAPI.TieredCacheSmartTopology; |
| 114 | export import TieredCacheSmartTopologyDeleteResponse = TieredCacheSmartTopologyAPI.TieredCacheSmartTopologyDeleteResponse; |
| 115 | export import TieredCacheSmartTopologyEditResponse = TieredCacheSmartTopologyAPI.TieredCacheSmartTopologyEditResponse; |
| 116 | export import TieredCacheSmartTopologyGetResponse = TieredCacheSmartTopologyAPI.TieredCacheSmartTopologyGetResponse; |
| 117 | export import TieredCacheSmartTopologyEditParams = TieredCacheSmartTopologyAPI.TieredCacheSmartTopologyEditParams; |
| 118 | export import Variants = VariantsAPI.Variants; |
| 119 | export import VariantListResponse = VariantsAPI.VariantListResponse; |
| 120 | export import VariantDeleteResponse = VariantsAPI.VariantDeleteResponse; |
| 121 | export import VariantEditResponse = VariantsAPI.VariantEditResponse; |
| 122 | export import VariantEditParams = VariantsAPI.VariantEditParams; |
| 123 | export import RegionalTieredCache = RegionalTieredCacheAPI.RegionalTieredCache; |
| 124 | export import RegionalTieredCacheEditResponse = RegionalTieredCacheAPI.RegionalTieredCacheEditResponse; |
| 125 | export import RegionalTieredCacheGetResponse = RegionalTieredCacheAPI.RegionalTieredCacheGetResponse; |
| 126 | export import RegionalTieredCacheEditParams = RegionalTieredCacheAPI.RegionalTieredCacheEditParams; |
| 127 | } |