3e25687a3feef340313777a7fb5858dbd01d35f2
cloudflare/Cloudflare\343\201\256Edge Cache\343\202\222API\343\201\213\343\202\211\345\211\212\351\231\244\343\201\231\343\202\213.md
... | ... | @@ -1,5 +1,31 @@ |
1 | 1 | <https://developers.cloudflare.com/api/operations/zone-purge> |
2 | 2 | |
3 | +どうやら、Free, Proプランからは`Purge All Cached Content`と`Purge Cached Content by URL`しか使えないっぽい。 |
|
4 | +手元では少なくともディレクトリ単位での削除は動作しなかった。 |
|
5 | + |
|
6 | +つまり、 |
|
7 | +```json |
|
8 | +{"files": ["http://www.example.com"]} |
|
9 | +``` |
|
10 | +としたとき、エッジキャッシュから削除されるのは`http://www.example.com`のコンテンツだけであり、`http://www.example.com/css/styles.css`は削除されない。 |
|
11 | + |
|
12 | +ここでややこしいのが、<https://developers.cloudflare.com/cache/how-to/purge-cache/>を見るとFree, Pro, Bussinessプランでもprefix削除できそうな気がするが、実際には単一のファイルを指定するか、ゾーン全体を消すしかないようだ。 |
|
13 | + |
|
14 | +Webコンソールから見ても、`URL: Purges assets in the Cloudflare cache that match the URL(s) exactly`と書いてあるので、完全一致のものしか消せないのだと思う。自分はProプランだが`URL`以外はグレーアウトしている。 |
|
15 | +[[/uploads/スクリーンショット 2024-09-25 215205.png]] |
|
16 | + |
|
17 | +まとめると以下のような対応付けだろうか?(間違っているかもしれない) |
|
18 | + |
|
19 | +| https://developers.cloudflare.com/api/operations/zone-purge#purge-all-cached-content | https://developers.cloudflare.com/cache/how-to/purge-cache/ | Supported Plan| |
|
20 | +|-|-|-| |
|
21 | +| Purge All Cached Content | Purge everything | Free, Pro, Bussiness | |
|
22 | +| Purge Cached Content by URL | Purge by single-file | Free, Pro, Bussiness | |
|
23 | +| Purge Cached Content by Tag, Host or Prefix | Purge cache by cache-tags | Enterprise | |
|
24 | +| Purge Cached Content by Tag, Host or Prefix | Purge cache by hostname | Enterprise | |
|
25 | +| Purge Cached Content by Tag, Host or Prefix | Purge cache by prefix(URL) | Enterprise | |
|
26 | + |
|
27 | +とりあえず、Purge everythingの例を示す。 |
|
28 | + |
|
3 | 29 | 環境変数は`.env`ファイルに入れる。 |
4 | 30 | |
5 | 31 | ```bash |
... | ... | @@ -12,4 +38,6 @@ curl "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \ |
12 | 38 | --header "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \ |
13 | 39 | --header "Content-Type: application/json" \ |
14 | 40 | --data '{"purge_everything": true}' |
15 | -``` |
|
... | ... | \ No newline at end of file |
0 | +``` |
|
1 | + |
|
2 | +間違っていたら教えてください。 |
|
... | ... | \ No newline at end of file |