Topic on Project:Support desk

Make the API use memcache?

5
93.184.128.26 (talkcontribs)

Is it possible to let the API make use of memcache?

I'd like to add a ~500 ms query on every article so memcache would come in handy.

Bawolff (talkcontribs)

The api already uses memcached if installed in appropriate places.

Sounds more like you want to use varnish/squid to cache full responses.

Subfader (talkcontribs)

Does it? I see $wgMemc only used in ApiMain.php for makeHelpMsg().

Can I request that on phabricator?

Bawolff (talkcontribs)

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.

Subfader (talkcontribs)

Thanks for the info, Bawolff. I don't use vanish or squid.

Reply to "Make the API use memcache?"