Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapbox API /styles/v1/{username} doesn't reflect latest style data

Tags:

mapbox

After calling Update Styles (POST) or Delete Styles (DELETE) using the Mapbox Styles API a subsequent call to List Styles (GET /styles/v1/{username}) returns stale style data. e.g. after calling DELETE and then calling CREATE the GET call will still return the deleted style!

Waiting about 5 minutes will usually return the latest, correct style data. Clearly some caching happening on the Mapbox end but deletes or updates should be reflected immediately.

Anybody confirm or provide a workaround?

like image 574
SmileSydney Avatar asked Oct 31 '25 12:10

SmileSydney


1 Answers

This is indeed because of how our default caching behavior works for these API endpoints.

The style list endpoint specifically has a default Cache-Control value of 5 minutes (i.e. Cache-Control: max-age=300). You can confirm by looking at the headers of the API response:

dev tools network tab with cache

It's possible to get around this default behavior by including the query parameter fresh=true in your request. Making your full request look like:

GET /styles/v1/{username}?access_token={scopes:styles.list}&fresh=true

Including this query parameter will cause the API to serve you a response with Cache-Control: no-cache instead, and you will see the most up-to-date style information associated with the username:

dev tools network tab with no-cache


⚠️ disclaimer: I currently work at Mapbox ⚠️

like image 107
riastrad Avatar answered Nov 03 '25 10:11

riastrad