You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/ai-gateway/configuration/caching.mdx
+23-9Lines changed: 23 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ description: Override caching settings on a per-request basis.
9
9
10
10
import { TabItem, Tabs } from"~/components";
11
11
12
-
Enable and customize your gateway cache to serve requests directly from Cloudflare’s cache, instead of the original model provider, for faster requests and cost savings.
12
+
Enable and customize your gateway cache to serve requests directly from Cloudflare's cache, instead of the original model provider, for faster requests and cost savings.
13
13
14
14
:::note
15
15
@@ -51,19 +51,29 @@ To check whether a response comes from cache or not, **cf-aig-cache-status** wil
51
51
52
52
In order to override the default cache behavior defined on the settings tab, you can, on a per-request basis, set headers for the following options:
53
53
54
-
### Skip cache (cf-skip-cache)
54
+
:::note
55
+
56
+
The following headers have been updated to new names, though the old headers will still function. We recommend updating to the new headers to ensure future compatibility:
57
+
58
+
`cf-cache-ttl` is now `cf-aig-cache-ttl`
59
+
60
+
`cf-skip-cache` is now `cf-aig-skip-cache`
61
+
62
+
:::
63
+
64
+
### Skip cache (cf-aig-skip-cache)
55
65
56
66
Skip cache refers to bypassing the cache and fetching the request directly from the original provider, without utilizing any cached copy.
57
67
58
-
You can use the header **cf-skip-cache** to bypass the cached version of the request.
68
+
You can use the header **cf-aig-skip-cache** to bypass the cached version of the request.
59
69
60
70
As an example, when submitting a request to OpenAI, include the header in the following manner:
Cache TTL, or Time To Live, is the duration a cached request remains valid before it expires and requires refreshing from the original source. You can use **cf-cache-ttl** to set the desired caching duration in milliseconds.
91
+
Cache TTL, or Time To Live, is the duration a cached request remains valid before it expires and is refreshed from the original source. You can use **cf-aig-cache-ttl** to set the desired caching duration in seconds. The minimum TTL is 60 seconds and the maximum TTL is one month.
82
92
83
-
For example, if you set a TTL of one hour, it means that a request is kept in the cache for an hour. Within that hour, an identical request will be served from the cache instead of the original API. After an hour, the cache expires and the request will go to the original API for a more recent response, and that response will repopulate the cache for the next hour.
93
+
For example, if you set a TTL of one hour, it means that a request is kept in the cache for an hour. Within that hour, an identical request will be served from the cache instead of the original API. After an hour, the cache expires and the request will go to the original API for a fresh response, and that response will repopulate the cache for the next hour.
84
94
85
95
As an example, when submitting a request to OpenAI, include the header in the following manner:
Custom cache keys let you override the default cache key in order to precisely set the cacheability setting for any resource. To override the default cache key, you can use the header **cf-aig-cache-key**.
107
117
108
-
When you use the **cf-aig-cache-key** header for the first time, you will receive a response from the provider. Subsequent requests with the same header will return the cached response. If the **cf-cache-ttl** header is used, responses will be cached according to the specified Cache Time To Live. Otherwise, responses will be cached according to the cache settings in the dashboard. If caching is not enabled for the gateway, responses will be cached for 5 minutes by default.
118
+
When you use the **cf-aig-cache-key** header for the first time, you will receive a response from the provider. Subsequent requests with the same header will return the cached response. If the **cf-aig-cache-ttl** header is used, responses will be cached according to the specified Cache Time To Live. Otherwise, responses will be cached according to the cache settings in the dashboard. If caching is not enabled for the gateway, responses will be cached for 5 minutes by default.
109
119
110
120
As an example, when submitting a request to OpenAI, include the header in the following manner:
Cache in AI Gateway is volatile. If two identical requests are sent simultaneously, the first request may not cache in time for the second request to use it, which may result in the second request retrieving data from the original source.
0 commit comments