API:データのキャッシュ

This page is a translated version of the page API:Caching data and the translation is 59% complete.

クライアントからのキャッシュの制御

HTTPプロトコルでは、Cache-Controlヘッダーに様々な値を指定することにより、ブラウザやウェブプロキシによるコンテンツのキャッシュを制御することができます。 (これは GET リクエストのみで動作します。) クライアントがAPIパラメータmaxagesmaxageによってこれらの値のmax-ages-maxageを設定することができます。

maxageはレスポンスをキャッシュする時間(秒単位)をブラウザに指定します。 smaxage does the same for shared proxies. In practice the latter is typically used to instruct the server-side reverse proxy (such as Wikimedia's Varnish ).

Errors are never cached. User-specific responses will be marked as Cache-Control: private so the browser will cache them but public proxies won't. Currently the API uses a logged-in user's language setting by default, so responses to logged-in users are always private. これは、uselang=contentのAPIパラメーター(T97096)を追加することで回避可能です。

キャッシュのヒット率の向上

A request is only served from cache if that exact URL has been cached. (E.g. if you make the same request with maxage=1800 and then with maxage=3600, the second won't be able to use the first's cache entry because the different maxage parameter makes the URL different.) If you pass a list of pages as a parameter, you might improve cache hit ratio by sorting and deduplicating them.

APIモジュールからのキャッシュの制御

キャッシュはApiMain::setCache*メソッドで指定します。 Typically caching is only going to be a concern in the query submodules, which should use getCacheMode method instead, which they inherit from ApiQueryBase.