Accelerate 常见问题解答
何时应该为 Prisma Accelerate 启用静态 IP?
¥When should I enable static IP for Prisma Accelerate?
如果你的安全设置需要 IP 许可列表,或者你正在实现仅允许来自受信任 IP 的访问的防火墙,请为 Accelerate 启用静态 IP,以确保数据库连接的受控和安全。
¥Enable static IP for Accelerate when your security setup requires IP allowlisting or if you're implementing firewalls that only permit access from trusted IPs, ensuring controlled and secure database connections.
了解更多关于 如何在平台控制台中为 Accelerate 启用静态 IP 的信息。
¥Learn more on how to enable static IP for Accelerate in the Platform Console.
什么是静态 IP?
¥What is a static IP?
静态 IP 地址是固定的 IPv4 或 IPv6 地址。与动态 IP 地址(可能不可预测地变化)不同,来自静态 IP 地址的流量很容易被识别。
¥A static IP address is an IPv4 or an IPv6 address that is fixed. Unlike dynamic IP addresses, which can change unpredictably, traffic from static IP addresses can be easily identified.
ℹ️ 要在现有或新的项目环境中启用 Accelerate 的静态 IP 支持,你的工作区需要使用我们的专业版或商业版。查看 定价页面 了解更多信息。
¥ℹ️ To enable static IP support for Accelerate within your existing or new project environment, your workspace will need to be on our Pro or Business plans. Take a look at the pricing page for more information.
为什么我有时会看到意外的缓存行为?
¥Why do I sometimes see unexpected cache behavior?
Accelerate 的缓存在项目负载较高时性能最佳。许多缓存操作(例如将数据提交到缓存和刷新陈旧数据)都是异步发生的。在对 Accelerate 进行基准测试时,我们建议使用循环或负载测试方法。这将更好地模拟高负载场景,并减少低频操作带来的异常值。
¥Accelerate's cache performs best when it observes a higher load from a project. Many cache operations, such as committing data to cache and refreshing stale data, happen asynchronously. When benchmarking Accelerate, we recommend doing so with loops or a load testing approach. This will mimic higher load scenarios better and reduce outliers from low frequency operations.
Prisma 操作通过 HTTP 发送到 Accelerate。因此,对 Accelerate 的第一个请求必须建立 HTTP 握手,因此可能会产生额外的延迟。我们正在探索未来减少初始请求延迟的方法。
¥Prisma operations are sent to Accelerate over HTTP. As a result, the first request to Accelerate must establish an HTTP handshake and may have additional latency as a result. We're exploring ways to reduce this initial request latency in the future.
Accelerate 的定价是多少?
¥What is the pricing of Accelerate?
你可以在我们的 Accelerate 定价页面 上找到更多详细信息。
¥You can find more details on our Accelerate pricing page
VS Code 无法识别 $extends
方法
¥VS Code does not recognize the $extends
method
如果你将 Prisma Client Accelerate 扩展添加到当前在 VS Code 中打开的现有项目中,编辑器可能无法立即识别 $extends
方法。
¥If you add the Prisma Client extension for Accelerate to an existing project that is currently open in VS Code, the editor might not immediately recognize the $extends
method.
这可能是 TypeScript 服务器尚未识别重新生成的 Prisma 客户端的问题。要解决此问题,你需要重新启动 TypeScript。
¥This might be an issue with the TypeScript server not yet recognizing the regenerated Prisma Client. To resolve this, you need to restart TypeScript.
-
在 VS Code 中,打开命令面板。你可以按 F1 或选择“视图”>“命令面板”来执行此操作。
¥In VS Code, open the Command Palette. You can do so when you press F1 or select View > Command Palette.
-
输入
typescript
并选择并运行 TypeScript:重新启动 TS 服务器命令。¥Enter
typescript
and select and run the TypeScript: Restart TS server command.
VS Code 现在应该可以识别 $extends
方法了。
¥VS Code should now recognize the $extends
method.
Accelerate 的缓存节点在哪些区域可用?
¥What regions are Accelerate's cache nodes available in?
Accelerate 在 Cloudflare 网络上运行,缓存命中由 Cloudflare 的 300 多个站点提供。你可以在此处找到 Accelerate 缓存节点可用的区域:https://www.cloudflare.com/network/。
¥Accelerate runs on Cloudflare's network and cache hits are served from Cloudflare's 300+ locations. You can find the regions where Accelerate's cache nodes are available here: https://www.cloudflare.com/network/.
Accelerate 的连接池在哪些区域可用?
¥What regions is Accelerate's connection pool available in?
当未指定缓存策略或发生缓存未命中时,Prisma 客户端查询将通过 Accelerate 的连接池路由。目前,查询可以通过 16 个可用位置中的任意选定区域进行路由。
¥When no cache strategy is specified or in the event of a cache miss, the Prisma Client query is routed through Accelerate's connection pool. Currently, queries can be routed through any chosen region among the 16 available locations.
目前,可用区域列表如下:
¥Currently, the list of available regions are:
-
亚太地区,孟买 (
ap-south-1
)¥Asia Pacific, Mumbai (
ap-south-1
) -
亚太地区,首尔 (
ap-northeast-2
)¥Asia Pacific, Seoul (
ap-northeast-2
) -
亚太地区,新加坡 (
ap-southeast-1
)¥Asia Pacific, Singapore (
ap-southeast-1
) -
亚太地区,悉尼 (
ap-southeast-2
)¥Asia Pacific, Sydney (
ap-southeast-2
) -
亚太地区,东京(
ap-northeast-1
)¥Asia Pacific, Tokyo (
ap-northeast-1
) -
加拿大中部 (
ca-central-1
)¥Canada, Central (
ca-central-1
) -
欧洲,法兰克福 (
eu-central-1
)¥Europe, Frankfurt (
eu-central-1
) -
欧洲,爱尔兰 (
eu-west-1
)¥Europe, Ireland (
eu-west-1
) -
欧洲,伦敦 (
eu-west-2
)¥Europe, London (
eu-west-2
) -
欧洲,巴黎 (
eu-west-3
)¥Europe, Paris (
eu-west-3
) -
欧洲,斯德哥尔摩 (
eu-north-1
)¥Europe, Stockholm (
eu-north-1
) -
南美洲,圣保罗 (
sa-east-1
)¥South America, Sao Paulo (
sa-east-1
) -
美国东部,北部弗吉尼亚 (
us-east-1
)¥US East, N. Virginia (
us-east-1
) -
美国东部,俄亥俄州 (
us-east-2
)¥US East, Ohio (
us-east-2
) -
美国西部,北部加利福尼亚州 (
us-west-1
)¥US West, N. California (
us-west-1
) -
美国西部,俄勒冈州 (
us-west-2
)¥US West, Oregon (
us-west-2
)
你还可以在设置 Accelerate 时查看可用的区域,或者访问 Prisma Cloud Platform dashboard 中“区域”部分下的“Accelerate”的“设置”选项卡来查看。
¥You can also view the available regions when you're about to set up Accelerate or by visiting the Settings tab for Accelerate under the Region section in the Prisma Cloud Platform dashboard.
Accelerate 如何知道从哪个区域获取缓存?
¥How does Accelerate know what region to fetch the cache from?
Accelerate 在底层使用 Cloudflare,而 Cloudflare 使用 Anycast 进行网络寻址和路由。传入的请求将被路由到最近的数据中心或其网络中能够高效处理请求的 "node"。要了解有关其工作原理的更多信息,我们建议你查看 Anycast。
¥Under the hood, Accelerate uses Cloudflare, which uses Anycast for network addressing and routing. An incoming request will be routed to the nearest data center or "node" in their network that has the capacity to process the request efficiently. To learn more about how this works, we recommend looking into Anycast.
如何在 Accelerate 上使缓存失效?
¥How can I invalidate a cache on Accelerate?
如果你使用的是 付费计划,你可以通过 $accelerate.invalidate
API 按需使缓存失效;或者,你可以在项目级别使整个缓存失效,每天最多五次。此限制基于 你的计划 设定。你可以通过 Accelerate 配置页面进行管理。
¥You can invalidate the cache on-demand via the $accelerate.invalidate
API if you're on a paid plan, or you can invalidate your entire cache, on a project level, a maximum of five times a day. This limit is set based on your plan. You can manage this via the Accelerate configuration page.
Accelerate 的一致性模型是什么?
¥What is Accelerate's consistency model?
Accelerate 没有一致性模型。它不是一个需要节点达成共识的分布式系统(因为数据仅存储在最靠近用户的缓存节点中)。但是,Accelerate 缓存节点中缓存的数据不会传播到其他节点,因此 Accelerate 在设计上不需要一致性模型。
¥Accelerate does not have a consistency model. It is not a distributed system where nodes need to reach a consensus (because data is only stored in the cache node(s) closest to the user). However, the data cached in Accelerate's cache nodes doesn't propagate to other nodes, so Accelerate by design doesn't need a consistency model.
Accelerate 实现了 读透缓存策略,特别适用于读取密集型工作负载。
¥Accelerate implements a read-through caching strategy particularly suitable for read-heavy workloads.
缓存数据的新鲜度取决于查询中定义的缓存策略。有关为你的查询选择正确的缓存策略的更多信息,请参阅 本节。
¥The freshness of the data served by the cache depends on the cache strategy defined in your query. Refer to this section for more information on selecting the right cache strategy for your query.
Accelerate 与其他缓存工具(例如 Redis)有何不同?
¥How is Accelerate different from other caching tools, such as Redis?
-
Accelerate 是一款专用缓存,允许你使用缓存策略在查询级别优化代码中的数据访问。另一方面,Redis 和 Memcached 等工具是通用缓存,旨在具有适应性和灵活性。
¥Accelerate is a specialized cache that allows you to optimize data access in code at the query level with a cache strategy. On the other hand, tools such as Redis and Memcached are general-purpose caches designed to be adaptable and flexible.
-
Accelerate 是一项托管服务,可减少构建和维护缓存服务的时间、风险和工程工作量。
¥Accelerate is a managed service that reduces the time, risk, and engineering effort of building and maintaining a cache service.
-
默认情况下,Accelerate 是全局分布式的,从而降低了查询延迟。其他缓存工具需要额外配置才能全局使用。
¥By default, Accelerate is globally distributed, reducing the latency of your queries. Other cache tools would require additional configuration to make them available globally.
何时不应该使用 Accelerate 的缓存功能?
¥When should I not use Accelerate's caching features?
Accelerate 是一个全局数据缓存和连接池,可让你在查询级别优化代码中的数据访问。虽然使用 Accelerate 进行缓存可以显著提升应用性能,但它并非始终是你用例的最佳选择。
¥Accelerate is a global data cache and connection pool that allows you to optimize data access in code at the query level. While caching with Accelerate can greatly boost the performance of your app, it may not always the best choice for your use case.
如果出现以下情况,Accelerate 的全局缓存功能可能不适合你的应用:
¥Accelerate's global cache feature may not be a good fit for your app if:
-
你的应用仅在特定区域内使用,并且你的应用服务器和数据库都位于同一网络的同一区域内。例如,如果你的应用服务器和数据库位于同一区域和网络,数据库查询速度可能会更快。但是,如果你的应用服务器与数据库位于不同的区域或网络,Accelerate 将加快你的查询速度,因为数据将缓存在距离你的应用最近的数据中心。
¥Your app is exclusively used within a specific region and both your application server and database are situated in that same region on the same network. For example, database queries will likely be much faster if your application server and database are in the same region and network. However, If your application server is in different regions or networks from your database, Accelerate will speed up your queries because the data will be cached in the closest data center to your application.
-
你只需要一个通用缓存。Accelerate 是一个连接池和专用缓存,它仅在代码中缓存数据库查询响应。通用缓存(例如 Redis)允许你缓存来自多个来源(例如外部 API)的数据,而 Accelerate 目前不支持这些来源。如果你对通用缓存感兴趣,请通过我们的 Discord 与我们分享你的反馈。
¥You only need a general-purpose cache. Accelerate is a connection pooler and a specialized cache that only caches your database query responses in code. A general-purpose cache, such as Redis, would allow you to cache data from multiple sources, such as external APIs, which Accelerate currently doesn't support. If general-purpose caching interests you, please share your feedback with us via our Discord.
-
你的应用数据始终需要在检索时保持最新,这使得制定合理的缓存策略变得困难。
¥Your application data always needs to be up-to-date on retrieval, making it difficult to establish a reasonable cache strategy.
即使不使用 Accelerate 的全局缓存,你仍然可以通过使用其连接池从 Accelerate 中获益匪浅,尤其是在无服务器或边缘功能中,因为这些功能难以管理和扩展数据库连接。你可以了解有关无服务器挑战 此处 的更多信息。
¥Even without using Accelerate's global cache, you can still greatly benefit from Accelerate by using its connection pool, especially in serverless or edge functions, where it is difficult to manage and scale database connections. You can learn more about the serverless challenge here.
我可以将 Accelerate 与其他 ORM/查询构建器/驱动程序一起使用吗?
¥Can I use Accelerate with other ORMs/query builders/drivers?
否我们目前没有计划支持其他 ORM/查询构建器或驱动程序。但是,如果你对其他库的支持感兴趣,请随时联系我们,并在 #help-and-questions
通道的 Discord 社区中告知我们。
¥No. We currently do not have any plans for supporting other ORMs/query builders or drivers. However, if you're interested in support for other libraries, feel free to reach out and let us know in our Discord community in the #help-and-questions
channel.
配置 cacheStrategy
时,ttl
参数的允许最大值是多少?
¥What is the maximum allowed value for the ttl
parameter when configuring cacheStrategy
?
生存时间 (ttl
) 参数最多可设置一年。但是,需要注意的是,如果缓存中的项目访问频率不高,它们可能会被逐出。
¥The Time-to-live (ttl
) parameter can be set for up to a year. However, it's important to note that items within the cache may be evicted if they are not frequently accessed.
根据我们的实验,我们发现缓存项可以保留大约 18 小时。如果项目被主动访问,它们可能会在缓存中保留较长时间,但这并不能保证。
¥Based on our experimentation, we’ve seen cache items persist for around 18 hours. While items may remain in the cache for an extended period if they are actively accessed, there is no guarantee.
注意:即使是频繁访问的项目也可能偶尔会被从缓存中移除。无论项目活跃度如何,它都不太可能存活超过一个月。
¥Note: Even frequently accessed items may occasionally be evicted from the cache. It's unlikely for an item to survive for up to or longer than a month, regardless of its activity level.
为什么 Accelerate 在服务中断期间不回退到直接连接字符串?
¥Why doesn’t Accelerate fall back to the direct connection string during a service disruption?
在极少数情况下,服务中断时,回退到直接连接将绕过连接池。这可能会耗尽数据库的可用连接,并导致数据库级别的其他问题。
¥In the rare event of a service disruption, falling back to a direct connection would bypass the connection pool. This could potentially deplete the database's available connections and cause other issues on the database level.
如果服务中断,建议在 状态页面 上进行验证。你可以联系 Prisma 的 支持渠道 寻求帮助。
¥If there is a service disruption, it's recommended to verify on the status page. You can reach out to one of Prisma's support channels for assistance.
注意:此外,值得注意的是,某些边缘函数运行时环境可能不支持与 Prisma ORM 的直接连接。更多详情,请参阅我们的 Edge 函数文档。
¥Note: Additionally, it's worth noting that some edge function runtime environments may not support direct connections with Prisma ORM. For further details, refer to our Edge functions documentation.
交互式事务中的每个查询是否单独计费?
¥Are each of the queries within an interactive transaction counted separately for billing?
是的,交互式事务 的计费基于事务中的各个操作。事务本身的启动、提交或回滚均免费。例如,以下查询包含两个计费查询:
¥Yes, interactive transactions are billed based on the individual operations within the transaction. There is no charge for the start, commit, or rollback of the transaction itself. For example, in the following query, there are two billable queries:
await prisma.$transaction(async (tx) => {
await tx.user.deleteMany({ where: { name: "John Doe" } });
await tx.user.createMany({ data });
});
但是,使用 用于顺序客户端操作的 $transaction
API 时,无论数组中的查询数量是多少,都只算作一次可计费查询。例如:
¥However, when using the $transaction
API for sequential client operations, regardless of the number of queries within the array, it counts as only one billable query. For example:
await prisma.$transaction([
prisma.user.deleteMany({ where: { name: "John Doe" } }),
prisma.user.createMany({ data }),
]);
如果你不需要 交互式事务,你可以使用 顺序操作事务 来节省成本并提高性能。顺序操作事务在 Accelerate 上性能更佳,因为它们只需一次往返数据库即可执行,而交互式事务则需要分别往返启动、提交以及事务中的每个单独操作。
¥If you don't need interactive transactions, you can save costs and improve performance by using sequential operations transactions. Sequential operations transactions perform better on Accelerate because they execute in one round-trip to the database, while interactive transactions require separate round-trips for start, commit, and each individual operation on the transaction.
我可以增加 Accelerate 查询时长和响应大小限制吗?
¥Can I increase my Accelerate query duration and response size limits?
是的,你可以根据你的订阅套餐提高 Accelerate 限额。以下是可配置的限制:
¥Yes, you can increase your Accelerate limits based on your subscription plan. Here are the configurable limits:
限制 | 入门 | 专业版计划 | 商业计划 |
---|---|---|---|
查询超时 | 最多 10 秒 | 最多 20 秒 | 最多 60 秒 |
交互式事务超时 | 最多 15 秒 | 最多 30 秒 | 最多 90 秒 |
响应大小 | 最多 5 MB | 最多 10 MB | 最多 20 MB |
查看 定价页面 文档,了解更多关于可用方案及其相应限制的详细信息。
¥Check the pricing page for more details on the available plans and their corresponding limits.
虽然你可以根据你的订阅方案增加这些限制,但仍然建议你优化数据库操作。在我们的故障排除指南中了解更多信息。
¥While you can increase these limits based on your subscription plan, it's still recommended to optimize your database operations. Learn more in our troubleshooting guide.
使缓存查询结果失效需要多长时间?
¥How long does it take to invalidate a cache query result?
由于需要全局清除缓存,因此很难提供具体的时间范围。但是,缓存的数据最终是一致的,通常会在几秒钟内传播到所有 PoP。在极少数情况下,这可能需要更长时间。
¥As the cache needs to be cleared globally, it is difficult to provide a specific time frame. However, the cached data is eventually consistent and typically propagates to all PoPs within a few seconds. In very rare cases, it may take longer.
以下是 演示应用,用于测试使缓存查询结果无效所需的时间。
¥Here is a demo app to test the time it takes to invalidate a cache query result.
Invalidate 和 Revalidate 之间有什么区别?
¥What is the difference between Invalidate and Revalidate?
失效:缓存条目将被删除,新的数据将在下次请求时获取,从而导致缓存未命中。这会删除过时的数据,但可能会导致响应速度变慢,直到重新填充缓存为止。
¥Invalidate: The cache entry is deleted, and new data will be fetched on the next request, causing a cache miss. This removes stale data but may lead to slower responses until the cache is repopulated.
重新验证:缓存条目会主动更新,确保下次请求使用缓存中的新数据。这可以使缓存保持有效,并通过避免缓存未命中来保持更快的响应时间。
¥Revalidate: The cache entry is updated proactively, ensuring the next request uses fresh data from the cache. This keeps the cache valid and maintains faster response times by avoiding cache misses.
什么是按需缓存失效?
¥What is on-demand cache invalidation?
按需缓存失效 允许应用在特定缓存数据发生变化时立即更新,而无需等待常规的缓存刷新周期。这可以使信息保持准确和最新。
¥On-demand cache invalidation lets applications instantly update specific cached data when it changes, instead of waiting for regular cache refresh cycles. This keeps information accurate and up-to-date for users.
何时应该使用缓存失效 API?
¥When should I use the cache invalidate API?
当数据一致性无法等待缓存的标准过期或重新验证时,缓存失效 API 至关重要。主要用例包括:
¥The cache invalidate API is essential when data consistency cannot wait for the cache’s standard expiration or revalidation. Key use cases include:
-
内容更新:当发生需要立即可见的关键更改(例如对已发布文章的编辑、产品更新或配置文件修改)时。
¥Content updates: When critical changes occur, such as edits to a published article, product updates, or profile modifications, that need to be visible immediately.
-
库存管理:在实时应用中,例如库存或预订系统,库存水平、可用性或预订状态必须反映最新信息。
¥Inventory management: In real-time applications, like inventory or booking systems, where stock levels, availability, or reservation statuses must reflect the latest information.
-
高优先级数据:对于时间敏感的数据,例如突发新闻或紧急通知,用户必须立即查看最新信息。
¥High-priority data: For time-sensitive data, like breaking news or urgent notifications, where it’s essential for users to see the most current information right away.
在这些情况下使用按需缓存失效有助于仅刷新必要的数据,从而保持系统性能,同时确保为用户提供准确、最新的信息。
¥Using on-demand cache invalidation in these scenarios helps keep only the necessary data refreshed, preserving system performance while ensuring accurate, up-to-date information for users.
Accelerate 如何统计查询次数并进行计费?
¥How does Accelerate count queries for billing?
Accelerate 在 Prisma 客户端调用级别统计查询次数。单个 Prisma 查询在底层可能会转换为多个 SQL 语句,但出于计费目的,它仅计为一个查询。这可确保计费直观、可预测,反映 Prisma 客户端的使用情况,而不是底层 SQL 操作的复杂性。
¥Accelerate counts queries at the Prisma Client invocation level. A single Prisma query may translate into multiple SQL statements under the hood, but it will only count as one query for billing purposes. This ensures straightforward, predictable billing that reflects the Prisma Client usage rather than the complexity of the underlying SQL operations.
无论查询是从缓存还是数据库提供,都会被计数。即使查询是从缓存中检索到的,它仍然会计入查询限制。
¥Queries are counted regardless of whether they are served from the cache or the database. Even if a query is retrieved from the cache, it still counts toward your query limit.
如何从 GitHub 登录切换到邮箱和密码登录?
¥How do I switch from GitHub login to email and password login?
如果你之前使用 GitHub 注册,现在想切换到邮箱和密码登录,请按以下步骤操作:
¥If you previously signed up using GitHub and want to switch to email and password login, follow these steps:
1. 验证你的 GitHub 电子邮件地址
¥ Verify Your GitHub Email Address
-
检查与你的 GitHub 账户关联的主要电子邮件地址(例如,从你的 GitHub 个人资料或通知设置中)。
¥Check the primary email address associated with your GitHub account (e.g., from your GitHub profile or notification settings).
2. 创建新的邮箱/密码账户
¥ Create a New Email/Password Account
-
前往邮箱/密码注册页面。
¥Go to the email/password sign-up page.
-
使用与你的 GitHub 账户关联的相同电子邮件地址创建新账户。
¥Use the same email address linked to your GitHub account to create the new account.
-
我们的系统会自动将你的新邮箱/密码账户连接到你现有的数据。
¥Our system will automatically connect your new email/password account to your existing data.
3. 测试你的登录
¥ Test Your Login
-
注销并尝试使用你的电子邮件和刚刚创建的密码登录。
¥Log out and try logging in with your email and the password you just created.
注意:如果你遇到任何问题,请联系我们的支持团队以获取账户关联方面的帮助。
¥Note: If you encounter any issues, please contact our support team for help linking your accounts.