我用 Cloudflare workers 实现 api 服务的反向代理,需求是:统计 api 的访问次数,如果在某个时间段内访问量超过上限就限制。
需要在 workers 里存储 api 的访问次数,原先是考虑使用 KV ,但是我看了 KV 文档,有这么一段:
Note that get may return stale values – if a given key has recently been read in a given location, changes to the key made in other locations may take up to 60 seconds to be visible. Refer to How KV works for more information on this topic.
来源: https://developers.cloudflare.com/workers/runtime-apis/kv/#reading-key-value-pairs
我理解大概意思是多个边缘节点读 /写 KV ,可能在某些边缘节点存在 60 秒的脏数据。
想问大佬:(1) 关于脏数据的理解是否正确 (2)workers 里做访问计数器,最佳操作是用什么存储方式?