Mapbox API/styles/v1/{username} 不反映最新的样式数据 [英] Mapbox API /styles/v1/{username} doesn't reflect latest style data
问题描述
在使用 Mapbox 样式 API 调用更新样式 (POST) 或删除样式 (DELETE) 后,对列表样式 (GET/styles/v1/{username}) 的后续调用将返回陈旧的样式数据.例如在调用 DELETE 和 CREATE 之后,GET 调用仍将返回已删除的样式!
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!
等待大约 5 分钟通常会返回最新的、正确的样式数据.显然,Mapbox 端发生了一些缓存,但应立即反映删除或更新.
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?
推荐答案
这确实是因为我们的默认缓存行为如何为这些 API 端点工作.
This is indeed because of how our default caching behavior works for these API endpoints.
样式列表端点的默认 Cache-Control 值为 5 分钟(即 Cache-Control: max-age=300
).您可以通过查看 API 响应的标头来确认:
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:
可以通过在请求中包含查询参数 fresh=true
来绕过此默认行为.使您的完整请求看起来像:
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
包含此查询参数将导致 API 使用 Cache-Control: no-cache
为您提供响应,您将看到与用户名关联的最新样式信息:
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:
⚠️ 免责声明:我目前在 Mapbox 工作 ⚠️
⚠️ disclaimer: I currently work at Mapbox ⚠️
这篇关于Mapbox API/styles/v1/{username} 不反映最新的样式数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!