cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/cache/cache.ts
138lines · 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 SmartTieredCacheAPI from 'cloudflare/resources/cache/smart-tiered-cache'; |
| 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 | smartTieredCache: SmartTieredCacheAPI.SmartTieredCache = new SmartTieredCacheAPI.SmartTieredCache( |
| 14 | this._client, |
| 15 | ); |
| 16 | variants: VariantsAPI.Variants = new VariantsAPI.Variants(this._client); |
| 17 | regionalTieredCache: RegionalTieredCacheAPI.RegionalTieredCache = |
| 18 | new RegionalTieredCacheAPI.RegionalTieredCache(this._client); |
| 19 | |
| 20 | /** |
| 21 | * ### Purge All Cached Content |
| 22 | * |
| 23 | * Removes ALL files from Cloudflare's cache. All tiers can purge everything. |
| 24 | * |
| 25 | * ### Purge Cached Content by URL |
| 26 | * |
| 27 | * Granularly removes one or more files from Cloudflare's cache by specifying URLs. |
| 28 | * All tiers can purge by URL. |
| 29 | * |
| 30 | * To purge files with custom cache keys, include the headers used to compute the |
| 31 | * cache key as in the example. If you have a device type or geo in your cache key, |
| 32 | * you will need to include the CF-Device-Type or CF-IPCountry headers. If you have |
| 33 | * lang in your cache key, you will need to include the Accept-Language header. |
| 34 | * |
| 35 | * **NB:** When including the Origin header, be sure to include the **scheme** and |
| 36 | * **hostname**. The port number can be omitted if it is the default port (80 for |
| 37 | * http, 443 for https), but must be included otherwise. |
| 38 | * |
| 39 | * ### Purge Cached Content by Tag, Host or Prefix |
| 40 | * |
| 41 | * Granularly removes one or more files from Cloudflare's cache either by |
| 42 | * specifying the host, the associated Cache-Tag, or a Prefix. Only Enterprise |
| 43 | * customers are permitted to purge by Tag, Host or Prefix. |
| 44 | * |
| 45 | * **NB:** Cache-Tag, host, and prefix purging each have a rate limit of 30,000 |
| 46 | * purge API calls in every 24 hour period. You may purge up to 30 tags, hosts, or |
| 47 | * prefixes in one API call. This rate limit can be raised for customers who need |
| 48 | * to purge at higher volume. |
| 49 | */ |
| 50 | purge(params: CachePurgeParams, options?: Core.RequestOptions): Core.APIPromise<CachePurgeResponse | null> { |
| 51 | const { zone_id, ...body } = params; |
| 52 | return ( |
| 53 | this._client.post(`/zones/${zone_id}/purge_cache`, { body, ...options }) as Core.APIPromise<{ |
| 54 | result: CachePurgeResponse | null; |
| 55 | }> |
| 56 | )._thenUnwrap((obj) => obj.result); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | export interface CachePurgeResponse { |
| 61 | /** |
| 62 | * Identifier |
| 63 | */ |
| 64 | id: string; |
| 65 | } |
| 66 | |
| 67 | export interface CachePurgeParams { |
| 68 | /** |
| 69 | * Path param: |
| 70 | */ |
| 71 | zone_id: string; |
| 72 | |
| 73 | /** |
| 74 | * Body param: |
| 75 | */ |
| 76 | files?: Array<string | CachePurgeParams.CachePurgeURLAndHeaders>; |
| 77 | |
| 78 | /** |
| 79 | * Body param: |
| 80 | */ |
| 81 | hosts?: Array<string>; |
| 82 | |
| 83 | /** |
| 84 | * Body param: |
| 85 | */ |
| 86 | prefixes?: Array<string>; |
| 87 | |
| 88 | /** |
| 89 | * Body param: |
| 90 | */ |
| 91 | purge_everything?: boolean; |
| 92 | |
| 93 | /** |
| 94 | * Body param: |
| 95 | */ |
| 96 | tags?: Array<string>; |
| 97 | } |
| 98 | |
| 99 | export namespace CachePurgeParams { |
| 100 | export interface CachePurgeURLAndHeaders { |
| 101 | headers?: unknown; |
| 102 | |
| 103 | url?: string; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | export namespace Cache { |
| 108 | export import CachePurgeResponse = CacheAPI.CachePurgeResponse; |
| 109 | export import CachePurgeParams = CacheAPI.CachePurgeParams; |
| 110 | export import CacheReserve = CacheReserveAPI.CacheReserve; |
| 111 | export import CacheReserveClearResponse = CacheReserveAPI.CacheReserveClearResponse; |
| 112 | export import CacheReserveEditResponse = CacheReserveAPI.CacheReserveEditResponse; |
| 113 | export import CacheReserveGetResponse = CacheReserveAPI.CacheReserveGetResponse; |
| 114 | export import CacheReserveStatusResponse = CacheReserveAPI.CacheReserveStatusResponse; |
| 115 | export import CacheReserveClearParams = CacheReserveAPI.CacheReserveClearParams; |
| 116 | export import CacheReserveEditParams = CacheReserveAPI.CacheReserveEditParams; |
| 117 | export import CacheReserveGetParams = CacheReserveAPI.CacheReserveGetParams; |
| 118 | export import CacheReserveStatusParams = CacheReserveAPI.CacheReserveStatusParams; |
| 119 | export import SmartTieredCache = SmartTieredCacheAPI.SmartTieredCache; |
| 120 | export import SmartTieredCacheDeleteResponse = SmartTieredCacheAPI.SmartTieredCacheDeleteResponse; |
| 121 | export import SmartTieredCacheEditResponse = SmartTieredCacheAPI.SmartTieredCacheEditResponse; |
| 122 | export import SmartTieredCacheGetResponse = SmartTieredCacheAPI.SmartTieredCacheGetResponse; |
| 123 | export import SmartTieredCacheDeleteParams = SmartTieredCacheAPI.SmartTieredCacheDeleteParams; |
| 124 | export import SmartTieredCacheEditParams = SmartTieredCacheAPI.SmartTieredCacheEditParams; |
| 125 | export import SmartTieredCacheGetParams = SmartTieredCacheAPI.SmartTieredCacheGetParams; |
| 126 | export import Variants = VariantsAPI.Variants; |
| 127 | export import CacheVariants = VariantsAPI.CacheVariants; |
| 128 | export import VariantEditResponse = VariantsAPI.VariantEditResponse; |
| 129 | export import VariantGetResponse = VariantsAPI.VariantGetResponse; |
| 130 | export import VariantDeleteParams = VariantsAPI.VariantDeleteParams; |
| 131 | export import VariantEditParams = VariantsAPI.VariantEditParams; |
| 132 | export import VariantGetParams = VariantsAPI.VariantGetParams; |
| 133 | export import RegionalTieredCache = RegionalTieredCacheAPI.RegionalTieredCache; |
| 134 | export import RegionalTieredCacheEditResponse = RegionalTieredCacheAPI.RegionalTieredCacheEditResponse; |
| 135 | export import RegionalTieredCacheGetResponse = RegionalTieredCacheAPI.RegionalTieredCacheGetResponse; |
| 136 | export import RegionalTieredCacheEditParams = RegionalTieredCacheAPI.RegionalTieredCacheEditParams; |
| 137 | export import RegionalTieredCacheGetParams = RegionalTieredCacheAPI.RegionalTieredCacheGetParams; |
| 138 | } |
| 139 | |