本页还没有译文
本页 32 段还没译成简体中文,下面显示的是英文原文。How KV works
还没翻译译自英文(developers.cloudflare.com)本页 32 段都还没译
模型写的
背景主张方法设置结果分析局限
KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare's data centers after access.KV is a global, low-latency, key-value data store. It stores data in a small number of centralized data centers, then caches that data in Cloudflare's data centers after access.KV 是全局键值存储,在 Cloudflare 数据中心缓存数据 数据存于集中数据中心,访问后被缓存KV 是全局键值存储,在 Cloudflare 数据中心缓存数据KV
KV supports exceptionally high read volumes with low latency, making it possible to build dynamic APIs that scale thanks to KV's built-in caching and global distribution. Requests which are not in cache and need to access the central stores can experience higher latencies.KV supports exceptionally high read volumes with low latency, making it possible to build dynamic APIs that scale thanks to KV's built-in caching and global distribution. Requests which are not in cache and need to access the central stores can experience higher latencies.KV 支持高读取量,但缓存未命中延迟更高 内置缓存和全局分布扩展读取;访问集中存储更慢KV 支持高读取量,但缓存未命中延迟更高读取量
Write data to KV and read data from KV
写入到集中存储;读取从区域和中心层级预热缓存
When you write to KV, your data is written to central data stores. Your data is not sent automatically to every location's cache.When you write to KV, your data is written to central data stores. Your data is not sent automatically to every location's cache.写入仅到集中数据存储,不发送到每个位置的缓存 缓存在后续读取时填充,而非写入时推送写入仅到集中数据存储,不发送到每个位置的缓存集中数据存储
Initial reads from a location do not have a cached value. Data must be read from the nearest regional tier, followed by a central tier, degrading finally to the central stores for a truly cold global read. While the first access is slow globally, subsequent requests are faster, especially if requests are concentrated in a single region.Data must be read from the nearest regional tier, followed by a central tier, degrading finally to the central stores for a truly cold global read. While the first access is slow globally, subsequent requests are faster, especially if requests are concentrated in a single region.冷全局读取经区域和中心层级降至集中存储 首次访问慢,但后续请求尤其是同区域请求更快冷全局读取经区域和中心层级降至集中存储冷读取
Hot and cold read
A hot read means that the data is cached on Cloudflare's edge network using the CDN, whether it is in a local cache or a regional cache. A cold read means that the data is not cached, so the data must be fetched from the central stores.A hot read means that the data is cached on Cloudflare's edge network using the CDN, whether it is in a local cache or a regional cache. A cold read means that the data is not cached, so the data must be fetched from the central stores.热读取来自边缘缓存,冷读取来自集中存储 通过 CDN 在 Cloudflare 边缘网络缓存区分两者热读取来自边缘缓存,冷读取来自集中存储热读取
Frequent reads from the same location return the cached value without reading from anywhere else, resulting in the fastest response times. KV operates diligently to update the cached values by refreshing from upper tier caches and central data stores before cache expires in the background.Frequent reads from the same location return the cached value without reading from anywhere else, resulting in the fastest response times. KV operates diligently to update the cached values by refreshing from upper tier caches and central data stores before cache expires in the background.同位置重复读取最快,直接返回缓存值 KV 在过期前后台从上层缓存和集中存储刷新同位置重复读取最快,直接返回缓存值缓存值
Refreshing from upper tiers and the central data stores in the background is done carefully so that assets that are being accessed continue to be kept served from the cache without any stalls.Refreshing from upper tiers and the central data stores in the background is done carefully so that assets that are being accessed continue to be kept served from the cache without any stalls.后台缓存刷新使资源继续服务而无停顿 刷新谨慎进行,使被访问资源持续由缓存提供后台缓存刷新使资源继续服务而无停顿缓存刷新
KV is optimized for high-read applications. It stores data centrally and uses a hybrid push/pull-based replication to store data in cache. KV is suitable for use cases where you need to write relatively infrequently, but read quickly and frequently. Infrequently read values are pulled from other data centers or the central stores, while more popular values are cached in the data centers they are requested from.KV is optimized for high-read applications. KV is suitable for use cases where you need to write relatively infrequently, but read quickly and frequently. Infrequently read values are pulled from other data centers or the central stores, while more popular values are cached in the data centers they are requested from.KV 适合少写多读场景,采用混合推拉复制缓存 热门值缓存在请求的数据中心,冷门值被拉取KV 适合少写多读场景,采用混合推拉复制缓存少写多读
Performance
将 cacheTtl 提高至超过默认 60 秒可改善 KV 读取性能
To improve KV performance, increase the cacheTtl parameter up from its default 60 seconds.To improve KV performance, increase the cacheTtl parameter up from its default 60 seconds.将 cacheTtl 参数提高到默认 60 秒以上以改善性能将 cacheTtl 参数提高到默认 60 秒以上以改善性能cacheTtl 参数
KV achieves high performance by caching which makes reads eventually-consistent with writes.KV achieves high performance by caching which makes reads eventually-consistent with writes.缓存带来高性能,但使读取与写入最终一致缓存带来高性能,但使读取与写入最终一致缓存
Changes are usually immediately visible in the Cloudflare global network location at which they are made. Changes may take up to 60 seconds or more to be visible in other global network locations as their cached versions of the data time out.Changes are usually immediately visible in the Cloudflare global network location at which they are made. Changes may take up to 60 seconds or more to be visible in other global network locations as their cached versions of the data time out.更改通常本地立即可见,其他地方需 60 秒或更久 其他位置等待其缓存数据超时更改通常本地立即可见,其他地方需 60 秒或更久更改
Negative lookups indicating that the key does not exist are also cached, so the same delay exists noticing a value is created as when a value is changed.Negative lookups indicating that the key does not exist are also cached, so the same delay exists noticing a value is created as when a value is changed.不存在键的否定查找也被缓存,延迟创建可见不存在键的否定查找也被缓存,延迟创建可见否定查找
Consistency
KV 最终一致;更改在其他位置可能需 60 秒或更久
KV achieves high performance by being eventually-consistent. At the Cloudflare global network location at which changes are made, these changes are usually immediately visible. However, this is not guaranteed and therefore it is not advised to rely on this behaviour. In other global network locations changes may take up to 60 seconds or more to be visible as their cached versions of the data time-out.KV achieves high performance by being eventually-consistent. However, this is not guaranteed and therefore it is not advised to rely on this behaviour. In other global network locations changes may take up to 60 seconds or more to be visible as their cached versions of the data time-out.更改通常但非保证本地立即可见,不应依赖 其他地方缓存超时使更改需 60 秒或更久更改通常但非保证本地立即可见,不应依赖最终一致
Visibility of changes takes longer in locations which have recently read a previous version of a given key (including reads that indicated the key did not exist, which are also cached locally).Visibility of changes takes longer in locations which have recently read a previous version of a given key (including reads that indicated the key did not exist, which are also cached locally).最近读过旧版本的位置更晚看到更改 本地缓存读取(包括否定读取)延迟新数据最近读过旧版本的位置更晚看到更改旧版本
Note
KV is not ideal for applications where you need support for atomic operations or where values must be read and written in a single transaction. If you need stronger consistency guarantees, consider using Durable Objects.KV is not ideal for applications where you need support for atomic operations or where values must be read and written in a single transaction. If you need stronger consistency guarantees, consider using Durable Objects.KV 不支持原子操作和单事务读写 如需更强一致性保证,可用 Durable ObjectsKV 不支持原子操作和单事务读写原子操作
An approach to achieve write-after-write consistency is to send all of your writes for a given KV key through a corresponding instance of a Durable Object, and then read that value from KV in other Workers. This is useful if you need more control over writes, but are satisfied with KV's read characteristics described above.An approach to achieve write-after-write consistency is to send all of your writes for a given KV key through a corresponding instance of a Durable Object, and then read that value from KV in other Workers. This is useful if you need more control over writes, but are satisfied with KV's read characteristics described above.将某键所有写入经 Durable Object 以实现写后写一致 然后在其他 Workers 从 KV 读取;适合满足于 KV 读取特性时将某键所有写入经 Durable Object 以实现写后写一致Durable Object
Guidance
KV 适合读多、可缓存的工作负载,不适合高频写单键
Workers KV is an eventually-consistent edge key-value store. That makes it ideal for read-heavy, highly cacheable workloads such as:Workers KV is an eventually-consistent edge key-value store. That makes it ideal for read-heavy, highly cacheable workloads such as:Workers KV 是最终一致的边缘存储,适合读多、可缓存工作负载Workers KV 是最终一致的边缘存储,适合读多、可缓存工作负载Workers KV
- Serving static assets
- Storing application configuration
- Storing user preferences
- Implementing allow-lists/deny-lists
- Caching
In these scenarios, Workers are invoked in a data center closest to the user and Workers KV data will be cached in that region for subsequent requests to minimize latency.In these scenarios, Workers are invoked in a data center closest to the user and Workers KV data will be cached in that region for subsequent requests to minimize latency.Workers 在离用户最近处运行,KV 数据在该区域缓存以降低延迟Workers 在离用户最近处运行,KV 数据在该区域缓存以降低延迟延迟
If you have a write-heavy Redis-type workload where you are updating the same key tens or hundreds of times per second, KV will not be an ideal fit. If you can revisit how your application writes to single key-value pairs and spread your writes across several discrete keys, Workers KV can suit your needs. Alternatively, Durable Objects provides a key-value API with higher writes per key rate limits.If you have a write-heavy Redis-type workload where you are updating the same key tens or hundreds of times per second, KV will not be an ideal fit. If you can revisit how your application writes to single key-value pairs and spread your writes across several discrete keys, Workers KV can suit your needs. Alternatively, Durable Objects provides a key-value API with higher writes per key rate limits.KV 不适合高频写同一键;分散写入或用 Durable Objects 拆分到多个离散键可适合 KV;Durable Objects 写限额更高KV 不适合高频写同一键;分散写入或用 Durable Objects高频写
Security
Workers KV 的数据安全详见数据安全文档
Refer to Data security documentation to understand how Workers KV secures data.Refer to Data security documentation to understand how Workers KV secures data.Workers KV 的数据安全见数据安全文档Workers KV 的数据安全见数据安全文档数据安全