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.
样式列表端点特别具有5分钟的默认Cache-Control值(即 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屋!