cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/cache/cache.ts
121lines · 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 CacheReservesAPI from 'cloudflare/resources/cache/cache-reserves'; |
| 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 | cacheReserves: CacheReservesAPI.CacheReserves = new CacheReservesAPI.CacheReserves(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 | identifier: string, |
| 51 | body: CachePurgeParams, |
| 52 | options?: Core.RequestOptions, |
| 53 | ): Core.APIPromise<CachePurgeResponse | null> { |
| 54 | return ( |
| 55 | this._client.post(`/zones/${identifier}/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.IHiNlFOkFlex |
| 71 | | CachePurgeParams.IHiNlFOkEverything |
| 72 | | CachePurgeParams.IHiNlFOkFiles; |
| 73 | |
| 74 | export namespace CachePurgeParams { |
| 75 | export interface IHiNlFOkFlex { |
| 76 | hosts?: Array<string>; |
| 77 | |
| 78 | prefixes?: Array<string>; |
| 79 | |
| 80 | tags?: Array<string>; |
| 81 | } |
| 82 | |
| 83 | export interface IHiNlFOkEverything { |
| 84 | purge_everything?: boolean; |
| 85 | } |
| 86 | |
| 87 | export interface IHiNlFOkFiles { |
| 88 | files?: Array<string | CachePurgeParams.IHiNlFOkFiles.IHiNlFOkURLAndHeaders>; |
| 89 | } |
| 90 | |
| 91 | export namespace IHiNlFOkFiles { |
| 92 | export interface IHiNlFOkURLAndHeaders { |
| 93 | headers?: unknown; |
| 94 | |
| 95 | url?: string; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | export namespace Cache { |
| 101 | export import CachePurgeResponse = CacheAPI.CachePurgeResponse; |
| 102 | export import CachePurgeParams = CacheAPI.CachePurgeParams; |
| 103 | export import CacheReserves = CacheReservesAPI.CacheReserves; |
| 104 | export import CacheReserveUpdateResponse = CacheReservesAPI.CacheReserveUpdateResponse; |
| 105 | export import CacheReserveListResponse = CacheReservesAPI.CacheReserveListResponse; |
| 106 | export import CacheReserveUpdateParams = CacheReservesAPI.CacheReserveUpdateParams; |
| 107 | export import TieredCacheSmartTopology = TieredCacheSmartTopologyAPI.TieredCacheSmartTopology; |
| 108 | export import TieredCacheSmartTopologyUpdateResponse = TieredCacheSmartTopologyAPI.TieredCacheSmartTopologyUpdateResponse; |
| 109 | export import TieredCacheSmartTopologyDeleteResponse = TieredCacheSmartTopologyAPI.TieredCacheSmartTopologyDeleteResponse; |
| 110 | export import TieredCacheSmartTopologyGetResponse = TieredCacheSmartTopologyAPI.TieredCacheSmartTopologyGetResponse; |
| 111 | export import TieredCacheSmartTopologyUpdateParams = TieredCacheSmartTopologyAPI.TieredCacheSmartTopologyUpdateParams; |
| 112 | export import Variants = VariantsAPI.Variants; |
| 113 | export import VariantUpdateResponse = VariantsAPI.VariantUpdateResponse; |
| 114 | export import VariantListResponse = VariantsAPI.VariantListResponse; |
| 115 | export import VariantDeleteResponse = VariantsAPI.VariantDeleteResponse; |
| 116 | export import VariantUpdateParams = VariantsAPI.VariantUpdateParams; |
| 117 | export import RegionalTieredCache = RegionalTieredCacheAPI.RegionalTieredCache; |
| 118 | export import RegionalTieredCacheUpdateResponse = RegionalTieredCacheAPI.RegionalTieredCacheUpdateResponse; |
| 119 | export import RegionalTieredCacheGetResponse = RegionalTieredCacheAPI.RegionalTieredCacheGetResponse; |
| 120 | export import RegionalTieredCacheUpdateParams = RegionalTieredCacheAPI.RegionalTieredCacheUpdateParams; |
| 121 | } |
| 122 | |