Thread:Project:Support desk/Make the API use memcache?/reply (3)

Subfader: I'm not sure I understand.

Most of the API is (relatively) cheap sql queries with no clear way to do appropriate expiration. Thus memcached is not usually used, although I believe there is a couple places where the API calls into other parts of MW which use memcached.

If you want to make a somewhat repetitive api query, and don't care if the result is mildly out of date, set the maxage and smaxage parameters when making the api request, to how many seconds you want to cache. The maxage controls how long the user caches the api request, where smaxage (if you have varnish or squid installed) controls how long to cache for everyone [Assuming the request isn't something private, like retrieving a deleted page, or making an edit].

For example, if you do https://commons.wikimedia.org/w/api.php?action=query&titles=File:Vincent_Willem_van_Gogh_038.jpg&prop=imageinfo&iiprop=extmetadata&smaxage=600

The first person to make that request will take the normal amount of time, however the response will be saved for up to 600 seconds, and anyone else who visits that exact url in the next 600 seconds will get the saved version, much faster, but potentially outdated.