CacheKey CacheKey( ≒ vcl_hash) defaultの... vcl_hash = req.url + req.http.hostを採用 IO利用時には qs が vcl_hash に渡る前に消されてしまうので、 vcl_hash = req.url + req.url.qs を採用したほうがいいのでは? となるかもしれないが、 IO利用時にはqsがセカンダリハッシュとして登録されるため不要 > The query string normalization described above happens prior to the vcl_hash subroutine and the IO query params are saved in a secondary hash to allow separation of the variants. ref ; https://developer.fastly.com/reference/io/#purging-images-from-the-fastly-cache
実装の注意点 実装方針 Shielding有効時は全てのPOPで同一 vcl が実行される また、タイミングによってFastly内でのTTLが2倍に設定されてしまう問題の解決のために Shield POPでのみ Object TTL、SC&CC Header を設定 Edge POPには SC header経由でTTLを伝え、Age分を減算したTTLを設定 > The HTTP Age header allows the backend to indicate that an object has already spent some time in a cache upstream before being served to Fastly. If the response includes an Age header with a positive value, that value will be subtracted from the response's main cache TTL. If the resulting TTL is negative, it is considered to be zero. If the TTL of a response is derived from an Expires header, any Age header also present on the response will not affect the TTL calculation. https://developer.fastly.com/learning/concepts/cache-freshness/#age Client Edge Shield CC header SC header
vclを見てみよう 実装はどうなる? shieldPOP時(req.backend.is_origin)のみCacheに関する設定を実施 Cache-Controleはclientに渡す設定、Surrogate-ControleはEdge用の設定。各種TTLの設定はS-Cからsubfieldで取ってきて set
実装前のおさらい > クラスタリング クラスタリングとは • default有効 ◦ POP内のnodeをdelivery/fetch に分けキャシュ効率を上げる • delivery node でCacheすることもある • Shieldingとは別概念。restartで無効 オブジェクトごとに最適なnodeを選択して、CHRを上げられるようにする工夫がある > In order to improve the likelihood of finding a hit in the cache, objects are assigned to specific storage servers based on each server handling a portion of the possible address space for cache keys, a mechanism known as consistent hashing. After calculating the object's cache key, the delivery node will transfer the request to the server which owns the address space containing that cache key. This second server will be responsible for fetching the object from origin and storing it, and in performing this role, is known as the fetch node. ref ; https://developer.fastly.com/learning/vcl/clustering/
実装前のおさらい > Clustering & Shielding POPのリクエストの流れ / Clustering,Shielding 有効時 • かなり多段でRequestを流すので、それを意識した実装をしたい > If a service has shielding enabled, a request that is not satisfiable from cache will transit two POPs. With clustering also enabled (which is the case by default), the request may encounter a maximum of two POPs and four sites on it's way to origin, as illustrated below: ref; https://developer.fastly.com/learning/concepts/pop/
POPs have the largest cache capacity on the Fastly network and are therefore good choices for shield locations. ref ; https://developer.fastly.com/learning/concepts/pop/#metro-pops Fastly yamagoya 2022 documentには書いてないが、API経由で叩けばメトロであることが分かる