From 9e1d3d8ed008289cdaa32ed6874566bec6ff0550 Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Mon, 2 Mar 2026 21:59:39 -0500 Subject: [PATCH 1/2] chore(docs): remove caching page --- .../docs/postgres/database/caching.mdx | 297 ------------------ apps/docs/vercel.json | 5 + 2 files changed, 5 insertions(+), 297 deletions(-) delete mode 100644 apps/docs/content/docs/postgres/database/caching.mdx diff --git a/apps/docs/content/docs/postgres/database/caching.mdx b/apps/docs/content/docs/postgres/database/caching.mdx deleted file mode 100644 index 61ad176459..0000000000 --- a/apps/docs/content/docs/postgres/database/caching.mdx +++ /dev/null @@ -1,297 +0,0 @@ ---- -title: Query caching -description: Configure and manage query caching in Prisma Postgres -url: /postgres/database/caching -metaTitle: Caching queries in Prisma Postgres -metaDescription: Learn about caching queries in Prisma Postgres ---- - -Prisma Postgres supports built-in query caching to reduce database load and improve query performance. You can configure cache behavior using the `cacheStrategy` option available in all read queries. - -This feature is powered by an internal caching layer enabled through [Prisma Accelerate](/accelerate), but you do not need to interact with Accelerate directly unless you're using your own database. - -## Setting up caching in Prisma Postgres - -To enable query caching in your Prisma Postgres project, you need to configure Accelerate caching and set up the client extension. Follow these steps: - -### 1. Enable caching in the Platform Console - -1. Go to the [Platform Console](https://console.prisma.io) and navigate to your project dashboard -2. In the "Connect to your database" section, click **Connect** -3. Toggle **Enable Accelerate caching** to activate the caching layer -4. Copy the generated connection string - -Your connection string will look like this: - -```text -DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=ey...." -``` - -Replace the connection string in your `.env` file with this new Accelerate-enabled URL. - -### 2. Install the Accelerate extension - -Install the required client extension in your project: - -```npm -npm install @prisma/extension-accelerate -``` - -### 3. Configure Prisma Client with caching - -Update your Prisma Client setup to use the Accelerate extension: - -```ts tab="standard" -import { PrismaClient } from "../generated/prisma/client"; -import { withAccelerate } from "@prisma/extension-accelerate"; - -const prisma = new PrismaClient({ - accelerateUrl: process.env.DATABASE_URL, -}).$extends(withAccelerate()); -``` - -```ts tab="edge" -import { PrismaClient } from "@prisma/client/edge"; -import { withAccelerate } from "@prisma/extension-accelerate"; - -const prisma = new PrismaClient({ - accelerateUrl: process.env.DATABASE_URL, -}).$extends(withAccelerate()); -``` - -### 4. Start caching your queries - -Once configured, you can add caching to any read query using the `cacheStrategy` option: - -```ts -await prisma.user.findMany({ - cacheStrategy: { - ttl: 60, // Cache for 60 seconds - }, -}); -``` - -Your caching setup is now complete! Continue reading to learn about different cache strategies and how to optimize them for your use case. - -## Cache strategies - -For all read queries in Prisma Client, you can define the `cacheStrategy` parameter that configures cache behavior. The cache strategy allows you to define two main characteristics of the cache: - -- **Time-to-live (TTL):** Duration in seconds a cached response is considered _fresh_. -- **Stale-while-Revalidating (SWR):** Duration in seconds a stale cache response is considered acceptable while the cache is refreshed in the background - -## Time-to-live (TTL) - -Time-to-Live (TTL) determines how long cached data is considered fresh. By specifying the `ttl` in seconds, you can control the duration for which data in the cache remains valid. When a read query is executed, if the cached response is within the `ttl` limit, Prisma Client retrieves the data from the cache without querying the database. If the cached data is not available or has expired, Prisma Client queries the database and stores the results in the cache for future requests. - -Use `ttl` in `cacheStrategy` and specify the TTL of the query in seconds: - -```javascript -await prisma.user.findMany({ - cacheStrategy: { - ttl: 60, // [!code ++] - }, -}); -``` - -With a specified TTL of 60 seconds, the majority of requests will result in -a cache hit throughout the TTL duration: - -![TTL](/img/accelerate/ttl.png) - -TTL is useful for reducing database load and latency for data that does not require frequent updates. - -### Invalidate the TTL and keep your cached query results up-to-date - -If your application requires real-time or near-real-time data, cache invalidation ensures that users see the most current data, even when using a large `ttl` (Time-To-Live). By invalidating your cache, you can bypass extended caching periods to show live data whenever it's needed. - -For example, if a dashboard displays customer information and a customer’s contact details change, TTL (Time-To-Live) settings ensure the cache automatically expires after a set duration. This allows the system to refresh only the updated data at the next access, ensuring support staff always see the latest information without manually refreshing the cache. - -However, in cases where immediate updates are required before the TTL expires, cache invalidation allows the system to proactively clear specific data from the cache. This forces a refresh of the updated information instantly, so support staff always have the most current details without waiting for the TTL to trigger. - -To invalidate a cached query result, you can add tags and then use the `$accelerate.invalidate` API. - -:::note - -On-demand cache invalidation is available with our paid plans. For more details, please see our [pricing](https://www.prisma.io/pricing#accelerate). - -::: - -To invalidate the query below, you need to provide the cache tag in the `$accelerate.invalidate` API: - -```ts -await prisma.user.findMany({ - cacheStrategy: { - ttl: 60, - tags: ["findMany_users"], // [!code ++] - }, -}); - -// This is how you would invalidate the cached query above. -await prisma.$accelerate.invalidate({ - // [!code ++] - tags: ["findMany_users"], // [!code ++] -}); // [!code ++] -``` - -## Stale-While-Revalidate (SWR) - -Stale-While-Revalidate (SWR) allows you to control how long Prisma Postgres can serve stale cache data while fetching fresh data in the background. When a read query is executed, Prisma Postgres checks the age of the cached response against the `swr` duration. If the cache data is within the `swr` limit, Prisma Postgres serves the stale data while simultaneously refreshing the cache by fetching the latest data from the database. - -Use `swr` in `cacheStrategy` and specify the SWR of the query in seconds: - -```javascript -await prisma.user.findMany({ - cacheStrategy: { - swr: 60, // [!code ++] - }, -}); -``` - -When specifying a SWR of 60 seconds, the cache serves stale data until the cache refreshes itself in the background after each request: - -![SWR](/img/accelerate/swr.png) - -### Invalidate the SWR and keep your cached query results up-to-date - -If your application requires real-time or near-real-time data, cache invalidation ensures that users see the most current data, even when using a large `swr` (Stale-While-Revalidate). By invalidating your cache, you can bypass extended caching periods to show live data whenever it's needed. - -For example, consider a dashboard that displays stock levels for products in a warehouse. With SWR (Stale-While-Revalidate) settings, the dashboard can immediately display the last known stock data, even if it’s slightly outdated, while new data is fetched in the background. This ensures that staff can continue working with recent information without waiting, with the stock levels updating as soon as revalidation completes. - -However, in cases where stock data needs to be updated immediately—for instance, if a product is low in stock and the count needs real-time accuracy—cache invalidation allows the system to proactively clear specific data from the cache. This forces a refresh of the latest stock data instantly, so staff always have the most up-to-date information without waiting for SWR to complete the revalidation. - -To invalidate a cached query result, you can add tags and then use the `$accelerate.invalidate` API. - -:::note - -On-demand cache invalidation is available with our paid plans. For more details, please see our [pricing](https://www.prisma.io/pricing#accelerate). - -::: - -To invalidate the query below, you need to provide the cache tag in the `$accelerate.invalidate` API: - -```ts -await prisma.user.findMany({ - cacheStrategy: { - swr: 60, - tags: ["findMany_users"], // [!code ++] - }, -}); - -// This is how you would invalidate the cached query above. -await prisma.$accelerate.invalidate({ - // [!code ++] - tags: ["findMany_users"], // [!code ++] -}); // [!code ++] -``` - -## Selecting a cache strategy - -Caching helps you improve query response times and reduce database load. However, it also means you might serve stale data to the client. Whether or not serving stale data is acceptable and to what extent depends on your use case. `ttl` and `swr` are parameters you can use the tweak the cache behavior. - -### Cache strategy using TTL - -Use TTL to reduce database load when stale cached data is acceptable. - -#### Use case: Product catalog in e-commerce applications - -Consider an e-commerce application with a product catalog that doesn't frequently change. By setting a `ttl` of, let's say, 1 hour, Prisma Client can serve cached product data for subsequent user requests within that hour without hitting the database. This significantly reduces the database load and improves the response time for product listing pages. - -**When to invalidate:** If there are critical updates to the catalog, such as a major price change or product availability adjustment, the [cache should be invalidated](/postgres/database/caching#on-demand-cache-invalidation) immediately to prevent customers from seeing outdated information. - -### Cache strategy using SWR - -Use SWR to respond quickly to requests with minimal stale data. While it does not reduce database load, it can improve response times significantly. - -#### Use case: User profile in social media platforms - -Imagine a social media platform where user profiles are frequently accessed. By leveraging `swr` with a duration of, let's say, 5 minutes, Prisma Postgres can serve the cached user profile information quickly, reducing the latency for profile pages. Meanwhile, in the background, it refreshes the cache after every request, ensuring that any updates made to the profile are eventually reflected for subsequent requests. - -**When to invalidate:** If a user makes significant updates to their profile, such as changing their profile picture or bio, the cache should be [invalidated](/postgres/database/caching#on-demand-cache-invalidation) immediately to ensure that followers see the latest updates without waiting for the SWR refresh. - -### Cache strategy using TTL + SWR - -For very fast response times and reduced database load, use both TTL and SWR. You can use this strategy to fine-tune your application’s tolerance for stale data. - -Use `ttl` and `swr` in `cacheStrategy` and specify the TTL and SWR of the query in seconds: - -```javascript -await prisma.user.findMany({ - cacheStrategy: { - ttl: 30, // [!code ++] - swr: 60, // [!code ++] - }, -}); -``` - -When specifying a TTL of 30 seconds and SWR of 60 seconds, the cache serves fresh data for the initial 30 seconds. Subsequently, it serves stale data until the cache refreshes itself in the background after each request: - -![Diagram showing cache behavior with TTL and SWR: fresh data for 30 seconds, then stale data served while background revalidation occurs.](/img/accelerate/ttl_and_swr.png) - -#### Use case: News articles - -Consider a news application where articles are frequently accessed but don't require real-time updates. By setting a `ttl` of 2 hours and an `swr` duration of 5 minutes, Prisma Client can serve cached articles quickly, reducing latency for readers. As long as the articles are within the `ttl`, users get fast responses. After the `ttl` expires, Prisma Client continues to serve the stale articles for up to an additional 5 minutes, revalidating the cache with the latest news from the database in response to a new query. This helps maintain a balance between performance and freshness. - -**When to invalidate:** If a critical update or breaking news article is published, the cache should be [invalidated](/postgres/database/caching#on-demand-cache-invalidation) immediately to ensure readers see the latest information without delay. This approach is especially useful for applications where certain news items may need to override the normal cache cycle for timeliness. - -## On-demand cache invalidation - -If your application requires real-time or near-real-time data, cache invalidation ensures that users see the most current data, even when using a large `ttl` (Time-To-Live) or `swr` (Stale-While-Revalidate) [cache strategy](/postgres/database/caching#cache-strategies). By invalidating your cache, you can bypass extended caching periods to show live data whenever it's needed. - -You can invalidate the cache using the [`$accelerate.invalidate` API](/accelerate/reference/api-reference#accelerateinvalidate): - -:::note - -To programmatically invalidate cached queries, a paid plan is required. See our [pricing for more details](https://www.prisma.io/pricing#accelerate). - -::: - -```ts -await prisma.user.findMany({ - where: { - email: { - contains: "alice@prisma.io", - }, - }, - cacheStrategy: { - swr: 60, - ttl: 60, - tags: ["emails_with_alice"], // [!code highlight] - }, -}); -``` - -You need to provide the cache tag in the `$accelerate.invalidate` API: - -```ts -try { - await prisma.$accelerate.invalidate({ - // [!code highlight] - tags: ["emails_with_alice"], // [!code highlight] - }); // [!code highlight] -} catch (e) { - if (e instanceof Prisma.PrismaClientKnownRequestError) { - // The .code property can be accessed in a type-safe manner - if (e.code === "P6003") { - console.log("The cache invalidation rate limit has been reached. Please try again later."); - } - } - throw e; -} -``` - -Explore the [demo app](https://pris.ly/test-cache-invalidation) to see how cached query results in Prisma Postgres are invalidated on demand, shown in a clear timeline. - -## Default cache strategy - -Prisma Postgres defaults to **no cache** to avoid unexpected issues. While caching can improve performance, incorrect usage may lead to errors. - -For instance, if a query is executed on a critical path without specifying a cache strategy, the result may be incorrect, with no clear explanation. This issue often arises when implicit caching is unintentionally left enabled. - -To avoid such problems, you must explicitly opt-in to caching. This ensures you are aware that caching is not enabled by default, preventing potential errors. - -:::note - -When no cache strategy is specified or during a cache miss, the cache layer routes all queries to the database through a connection pool instance near the database region. - -::: diff --git a/apps/docs/vercel.json b/apps/docs/vercel.json index 4a7660de0d..258d88a3da 100644 --- a/apps/docs/vercel.json +++ b/apps/docs/vercel.json @@ -5609,6 +5609,11 @@ "source": "/docs/orm/prisma-client/queries/relation-aggregates", "destination": "/docs/orm/prisma-client/queries/aggregation-grouping-summarizing", "permanent": true + }, + { + "source": "/docs/postgres/database/caching", + "destination": "/docs/postgres", + "permanent": true } ] } From 1372d8f6ca14261c68e424b563966a47e15c6ce0 Mon Sep 17 00:00:00 2001 From: Mike Hartington Date: Mon, 2 Mar 2026 22:12:19 -0500 Subject: [PATCH 2/2] chore(docs): fix links --- .../prisma-postgres.mdx | 1 - .../prisma-orm/quickstart/prisma-postgres.mdx | 1 - .../(index)/prisma-postgres/from-the-cli.mdx | 2 +- .../prisma-postgres/quickstart/prisma-orm.mdx | 1 - apps/docs/content/docs/accelerate/caching.mdx | 2 -- apps/docs/content/docs/accelerate/compare.mdx | 4 ++-- .../docs/accelerate/getting-started.mdx | 22 +------------------ .../docs/content/docs/accelerate/more/faq.mdx | 8 +++---- .../accelerate/reference/api-reference.mdx | 2 +- .../guides/authentication/clerk/astro.mdx | 1 - .../guides/authentication/clerk/nextjs.mdx | 1 - .../guides/deployment/cloudflare-workers.mdx | 1 - .../content/docs/guides/frameworks/astro.mdx | 1 - .../content/docs/guides/frameworks/elysia.mdx | 1 - .../content/docs/guides/frameworks/hono.mdx | 1 - .../docs/guides/frameworks/solid-start.mdx | 1 - .../docs/guides/frameworks/sveltekit.mdx | 1 - .../docs/guides/integrations/ai-sdk.mdx | 1 - .../docs/guides/integrations/shopify.mdx | 1 - .../postgres/database/local-development.mdx | 12 ---------- .../content/docs/postgres/database/meta.json | 1 - apps/docs/content/docs/postgres/faq.mdx | 13 +++-------- 22 files changed, 11 insertions(+), 68 deletions(-) diff --git a/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/prisma-postgres.mdx b/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/prisma-postgres.mdx index 0cd5da71e7..0d8208f946 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/prisma-postgres.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/prisma-postgres.mdx @@ -246,4 +246,3 @@ You've successfully set up Prisma ORM. Here's what you can explore next: - [Prisma Config reference](/orm/reference/prisma-config-reference) - [Database introspection](/orm/prisma-schema/introspection) - [Prisma Migrate](/orm/prisma-migrate) -- [Cache your queries](/postgres/database/caching#setting-up-caching-in-prisma-postgres) diff --git a/apps/docs/content/docs/(index)/prisma-orm/quickstart/prisma-postgres.mdx b/apps/docs/content/docs/(index)/prisma-orm/quickstart/prisma-postgres.mdx index 25a7be7cec..b5c6d93a36 100644 --- a/apps/docs/content/docs/(index)/prisma-orm/quickstart/prisma-postgres.mdx +++ b/apps/docs/content/docs/(index)/prisma-orm/quickstart/prisma-postgres.mdx @@ -277,4 +277,3 @@ You've successfully set up Prisma ORM. Here's what you can explore next: - [Prisma Postgres documentation](/postgres) - [Prisma Config reference](/orm/reference/prisma-config-reference) - [Database connection management](/orm/prisma-client/setup-and-configuration/databases-connections) -- [Cache your queries](/postgres/database/caching#setting-up-caching-in-prisma-postgres) diff --git a/apps/docs/content/docs/(index)/prisma-postgres/from-the-cli.mdx b/apps/docs/content/docs/(index)/prisma-postgres/from-the-cli.mdx index 983f24c01e..ee9790caa2 100644 --- a/apps/docs/content/docs/(index)/prisma-postgres/from-the-cli.mdx +++ b/apps/docs/content/docs/(index)/prisma-postgres/from-the-cli.mdx @@ -442,7 +442,7 @@ This time, you're seeing two `User` objects being printed. Both of them have a ` ## Next steps -You just got your feet wet with a basic Prisma Postgres setup. If you want to explore more complex queries, such as [adding caching functionality](/postgres/database/caching#setting-up-caching-in-prisma-postgres), check out the official [Quickstart](/prisma-orm/quickstart/prisma-postgres). +You just got your feet wet with a basic Prisma Postgres setup. Check out the official [Quickstart](/prisma-orm/quickstart/prisma-postgres). ### View and edit data in Prisma Studio diff --git a/apps/docs/content/docs/(index)/prisma-postgres/quickstart/prisma-orm.mdx b/apps/docs/content/docs/(index)/prisma-postgres/quickstart/prisma-orm.mdx index 71555fd246..5cf73549a8 100644 --- a/apps/docs/content/docs/(index)/prisma-postgres/quickstart/prisma-orm.mdx +++ b/apps/docs/content/docs/(index)/prisma-postgres/quickstart/prisma-orm.mdx @@ -251,4 +251,3 @@ You've successfully set up Prisma ORM. Here's what you can explore next: - [Prisma Postgres documentation](/postgres) - [Prisma Config reference](/orm/reference/prisma-config-reference) - [Database connection management](/orm/prisma-client/setup-and-configuration/databases-connections) -- [Cache your queries](/postgres/database/caching#setting-up-caching-in-prisma-postgres) diff --git a/apps/docs/content/docs/accelerate/caching.mdx b/apps/docs/content/docs/accelerate/caching.mdx index c1e3b7ed57..fa18f84137 100644 --- a/apps/docs/content/docs/accelerate/caching.mdx +++ b/apps/docs/content/docs/accelerate/caching.mdx @@ -7,5 +7,3 @@ metaDescription: Learn everything you need to know to use Accelerate's global da --- Prisma Accelerate provides global caching for read queries using TTL, Stale-While-Revalidate (SWR), or a combination of both. It's included as part of Prisma Postgres, but can also be used with your own database by enabling Accelerate in the [Prisma Data Platform](https://console.prisma.io?utm_source=docs) and [configuring it with your database](/accelerate/getting-started). - -This content has moved — learn more on the updated [Caching in Accelerate](/postgres/database/caching) page. diff --git a/apps/docs/content/docs/accelerate/compare.mdx b/apps/docs/content/docs/accelerate/compare.mdx index 10ca9b9403..414aa8d184 100644 --- a/apps/docs/content/docs/accelerate/compare.mdx +++ b/apps/docs/content/docs/accelerate/compare.mdx @@ -39,7 +39,7 @@ Prisma Accelerate offers a powerful global cache, so you can serve data to your **Why are these important?** -- Since Accelerate extends the Prisma client, you can control caching policies directly from your codebase with just an extra line of code. Integration is seamless. Here is an example using [the stale-while-revalidating caching strategy](/postgres/database/caching#stale-while-revalidate-swr): +- Since Accelerate extends the Prisma client, you can control caching policies directly from your codebase with just an extra line of code. Integration is seamless. Here is an example using the stale-while-revalidating caching strategy: ```jsx await prisma.user.findMany({ cacheStrategy: { @@ -49,7 +49,7 @@ Prisma Accelerate offers a powerful global cache, so you can serve data to your ``` - Query level cache policies are critical for serious applications, so that you can control which queries are cached, and the characteristics of the policy. You may want certain data in your app to be cached for several days, other data to be cached for a just a few minutes, and other data to be not cached at all. This is only possible with Prisma Accelerate. - Authenticating with an API key can be a helpful security measure, allowing you to decouple database credentials from application secrets. Easily rotate API keys as often as you like, without needing any credential changes in your database -- Automatic cache updates means that the cache is automatically updated when a change in the database occurs. With Accelerate, you are in control of how the cache is invalidated, using [various caching strategies](/postgres/database/caching). +- Automatic cache updates means that the cache is automatically updated when a change in the database occurs. With Accelerate, you are in control of how the cache is invalidated, using [various caching strategies](/accelerate/caching). ## Accelerate connection pool diff --git a/apps/docs/content/docs/accelerate/getting-started.mdx b/apps/docs/content/docs/accelerate/getting-started.mdx index 9f41f3b0d2..f665ec19e5 100644 --- a/apps/docs/content/docs/accelerate/getting-started.mdx +++ b/apps/docs/content/docs/accelerate/getting-started.mdx @@ -174,26 +174,6 @@ If you simply want to take advantage of Accelerate's connection pooling feature By enabling Accelerate and supplying the Accelerate connection string, your queries now use the connection pooler by default. -#### Define a cache strategy - -Update a query with the new `cacheStrategy` property which allows you to define a cache strategy for that specific query: - -```ts -const user = await prisma.user.findMany({ - where: { - email: { - contains: "alice@prisma.io", - }, - }, - cacheStrategy: { swr: 60, ttl: 60 }, -}); -``` - -In the example above, `swr: 60` and `ttl: 60` means Accelerate will serve cached data for 60 seconds and then another 60 seconds while Accelerate fetches fresh data in the background. - -You should now see improved performance for your cached queries. - -For information about which strategy best serves your application, see [Select a cache strategy](/postgres/database/caching#selecting-a-cache-strategy). :::info @@ -203,7 +183,7 @@ As of Prisma version `5.2.0` you can use Prisma Studio with the Accelerate conne #### Invalidate the cache and keep your cached query results up-to-date -If your application requires real-time or near-real-time data, cache invalidation ensures that users see the most current data, even when using a large `ttl` (Time-To-Live) or `swr` (Stale-While-Revalidate) [cache strategy](/postgres/database/caching#cache-strategies). By invalidating your cache, you can bypass extended caching periods to show live data whenever it's needed. +If your application requires real-time or near-real-time data, cache invalidation ensures that users see the most current data, even when using a large `ttl` (Time-To-Live) or `swr` (Stale-While-Revalidate) [cache strategy](/accelerate/caching). By invalidating your cache, you can bypass extended caching periods to show live data whenever it's needed. For example, if a dashboard displays customer information and a customer’s contact details change, cache invalidation allows you to refresh only that data instantly, ensuring support staff always see the latest information without waiting for the cache to expire. diff --git a/apps/docs/content/docs/accelerate/more/faq.mdx b/apps/docs/content/docs/accelerate/more/faq.mdx index b96e51da1f..f3ff6627cd 100644 --- a/apps/docs/content/docs/accelerate/more/faq.mdx +++ b/apps/docs/content/docs/accelerate/more/faq.mdx @@ -88,8 +88,6 @@ Accelerate does not have a consistency model. It is not a distributed system whe Accelerate implements a [read-through caching strategy](https://www.prisma.io/dataguide/managing-databases/introduction-database-caching#read-through) 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](/postgres/database/caching#selecting-a-cache-strategy) for more information on selecting the right cache strategy for your query. - ## How is Accelerate different from other caching tools, such as Redis? - 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. @@ -116,7 +114,7 @@ No. We currently do not have any plans for supporting other ORMs/query builders ## What is the maximum allowed value for the `ttl` parameter when configuring `cacheStrategy`? -The [Time-to-live](/postgres/database/caching#time-to-live-ttl) (`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. +The [Time-to-live](/accelerate/caching) (`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. 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. @@ -182,11 +180,11 @@ Here is a [demo app](https://pris.ly/test-cache-invalidation) to test the time i ## What is on-demand cache invalidation? -[On-demand cache invalidation](/postgres/database/caching#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. +[On-demand cache invalidation](/accelerate/caching) 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. ## When should I use the cache invalidate API? -The [cache invalidate API](/postgres/database/caching#on-demand-cache-invalidation) is essential when data consistency cannot wait for the cache’s standard expiration or revalidation. Key use cases include: +The [cache invalidate API](/accelerate/caching) 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. diff --git a/apps/docs/content/docs/accelerate/reference/api-reference.mdx b/apps/docs/content/docs/accelerate/reference/api-reference.mdx index 51926f52bf..bb62e68278 100644 --- a/apps/docs/content/docs/accelerate/reference/api-reference.mdx +++ b/apps/docs/content/docs/accelerate/reference/api-reference.mdx @@ -20,7 +20,7 @@ All example are based on the `User` model. ## `cacheStrategy` -With the Accelerate extension for Prisma Client, you can use the `cacheStrategy` parameter for model queries and use the [`ttl`](/postgres/database/caching#time-to-live-ttl) and [`swr`](/postgres/database/caching#stale-while-revalidate-swr) parameters to define a cache strategy for Accelerate. The Accelerate extension requires that you install Prisma Client version `4.10.0`. +With the Accelerate extension for Prisma Client, you can use the `cacheStrategy` parameter for model queries and use the [`ttl`](/accelerate/caching) and [`swr`](/accelerate/caching) parameters to define a cache strategy for Accelerate. The Accelerate extension requires that you install Prisma Client version `4.10.0`. ### Options diff --git a/apps/docs/content/docs/guides/authentication/clerk/astro.mdx b/apps/docs/content/docs/guides/authentication/clerk/astro.mdx index b1ed6052ff..d5306938d1 100644 --- a/apps/docs/content/docs/guides/authentication/clerk/astro.mdx +++ b/apps/docs/content/docs/guides/authentication/clerk/astro.mdx @@ -512,7 +512,6 @@ Now that you have a working Astro app with Clerk authentication and Prisma conne - Build protected API routes that require authentication - Extend your schema with additional models related to users - Deploy to your preferred hosting platform and set your production webhook URL in Clerk -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ### More info diff --git a/apps/docs/content/docs/guides/authentication/clerk/nextjs.mdx b/apps/docs/content/docs/guides/authentication/clerk/nextjs.mdx index 5ecc1ee53c..e1e5b63a83 100644 --- a/apps/docs/content/docs/guides/authentication/clerk/nextjs.mdx +++ b/apps/docs/content/docs/guides/authentication/clerk/nextjs.mdx @@ -822,7 +822,6 @@ Below are some next steps to explore, as well as some more resources to help you - Add delete functionality to posts and users. - Add a search bar to filter posts. - Deploy to Vercel and set your production webhook URL in Clerk. -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ### More Info diff --git a/apps/docs/content/docs/guides/deployment/cloudflare-workers.mdx b/apps/docs/content/docs/guides/deployment/cloudflare-workers.mdx index 9bcc3764d0..a0a9a258ff 100644 --- a/apps/docs/content/docs/guides/deployment/cloudflare-workers.mdx +++ b/apps/docs/content/docs/guides/deployment/cloudflare-workers.mdx @@ -403,7 +403,6 @@ Now that you have a working Cloudflare Workers app connected to a Prisma Postgre - Extend your Prisma schema with more models and relationships - Implement authentication and authorization - Use [Hono](https://hono.dev/) for a more robust routing framework with Cloudflare Workers (see our [Hono guide](/guides/frameworks/hono)) -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ### More info diff --git a/apps/docs/content/docs/guides/frameworks/astro.mdx b/apps/docs/content/docs/guides/frameworks/astro.mdx index bccf1a9ea5..f71b78e3f1 100644 --- a/apps/docs/content/docs/guides/frameworks/astro.mdx +++ b/apps/docs/content/docs/guides/frameworks/astro.mdx @@ -386,7 +386,6 @@ Now that you have a working Astro app connected to a Prisma Postgres database, y - Extend your Prisma schema with more models and relationships - Add create/update/delete routes and forms - Explore authentication and validation -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ### More Info diff --git a/apps/docs/content/docs/guides/frameworks/elysia.mdx b/apps/docs/content/docs/guides/frameworks/elysia.mdx index 886a872f19..c8540e2226 100644 --- a/apps/docs/content/docs/guides/frameworks/elysia.mdx +++ b/apps/docs/content/docs/guides/frameworks/elysia.mdx @@ -434,7 +434,6 @@ Now that you have a working Elysia app connected to a Prisma Postgres database, - Extend your Prisma schema with more models and relationships - Add update and delete endpoints - Explore authentication with [Elysia plugins](https://elysiajs.com/plugins/overview.html) -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance - Use [Eden](https://elysiajs.com/eden/overview.html) for end-to-end type-safe API calls ### More info diff --git a/apps/docs/content/docs/guides/frameworks/hono.mdx b/apps/docs/content/docs/guides/frameworks/hono.mdx index dedeb39a72..43073be498 100644 --- a/apps/docs/content/docs/guides/frameworks/hono.mdx +++ b/apps/docs/content/docs/guides/frameworks/hono.mdx @@ -350,7 +350,6 @@ Now that you have a working Hono app connected to a Prisma Postgres database, yo - Extend your Prisma schema with more models and relationships - Add create/update/delete routes and forms - Explore authentication and validation -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ### More Info diff --git a/apps/docs/content/docs/guides/frameworks/solid-start.mdx b/apps/docs/content/docs/guides/frameworks/solid-start.mdx index 846499ffe9..7cae2215d9 100644 --- a/apps/docs/content/docs/guides/frameworks/solid-start.mdx +++ b/apps/docs/content/docs/guides/frameworks/solid-start.mdx @@ -435,7 +435,6 @@ Now that you have a working SolidStart app connected to a Prisma Postgres databa - Extend your Prisma schema with more models and relationships - Add create/update/delete routes and forms - Explore authentication, validation, and optimistic updates -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ## More Info diff --git a/apps/docs/content/docs/guides/frameworks/sveltekit.mdx b/apps/docs/content/docs/guides/frameworks/sveltekit.mdx index 73a5d6b1fe..8f988cc7eb 100644 --- a/apps/docs/content/docs/guides/frameworks/sveltekit.mdx +++ b/apps/docs/content/docs/guides/frameworks/sveltekit.mdx @@ -370,7 +370,6 @@ Now that you have a working SvelteKit app connected to a Prisma Postgres databas - Extend your Prisma schema with more models and relationships - Add create/update/delete routes and forms - Explore authentication and validation -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ### More Info diff --git a/apps/docs/content/docs/guides/integrations/ai-sdk.mdx b/apps/docs/content/docs/guides/integrations/ai-sdk.mdx index 1b34c2b78d..dc23d4c59b 100644 --- a/apps/docs/content/docs/guides/integrations/ai-sdk.mdx +++ b/apps/docs/content/docs/guides/integrations/ai-sdk.mdx @@ -629,7 +629,6 @@ Now that you have a working AI SDK chat application connected to a Prisma Postgr - Extend your Prisma schema with more models and relationships - Add create/update/delete routes and forms - Explore authentication and validation -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ### More Info diff --git a/apps/docs/content/docs/guides/integrations/shopify.mdx b/apps/docs/content/docs/guides/integrations/shopify.mdx index 05be2f575f..9dd125c974 100644 --- a/apps/docs/content/docs/guides/integrations/shopify.mdx +++ b/apps/docs/content/docs/guides/integrations/shopify.mdx @@ -732,7 +732,6 @@ Now that you have a working Shopify app connected to a Prisma Postgres database, - Extend your Prisma schema with more models and relationships - Add create/update/delete routes and forms -- Enable query caching with [Prisma Postgres](/postgres/database/caching) for better performance ### More Info diff --git a/apps/docs/content/docs/postgres/database/local-development.mdx b/apps/docs/content/docs/postgres/database/local-development.mdx index b94939f8f2..efc289bb29 100644 --- a/apps/docs/content/docs/postgres/database/local-development.mdx +++ b/apps/docs/content/docs/postgres/database/local-development.mdx @@ -280,18 +280,6 @@ Notes: ## Known limitations -### Caching is mocked locally - -[Prisma Postgres caching](/postgres/database/caching) is simulated locally. Queries always directly interact with the local Prisma Postgres instance, bypassing cache configurations: - -```typescript -const users = await prisma.user.findMany({ - cache: { ttl: 60 }, -}); -``` - -Caching works normally when you're using Prisma Postgres in staging and production. - ### Single connection only The local Prisma Postgres database server accepts one connection at a time. Additional connection attempts queue until the active connection closes. This constraint is sufficient for most local development and testing scenarios. diff --git a/apps/docs/content/docs/postgres/database/meta.json b/apps/docs/content/docs/postgres/database/meta.json index b02eff397d..bf528825e1 100644 --- a/apps/docs/content/docs/postgres/database/meta.json +++ b/apps/docs/content/docs/postgres/database/meta.json @@ -1,7 +1,6 @@ { "title": "Database", "pages": [ - "caching", "connection-pooling", "direct-connections", "backups", diff --git a/apps/docs/content/docs/postgres/faq.mdx b/apps/docs/content/docs/postgres/faq.mdx index 439bb06d3b..403df93f94 100644 --- a/apps/docs/content/docs/postgres/faq.mdx +++ b/apps/docs/content/docs/postgres/faq.mdx @@ -252,13 +252,6 @@ Under the hood, Prisma Postgres's cache layer uses Cloudflare, which uses [Anyca You can invalidate the cache on-demand via the [`$accelerate.invalidate` API](/accelerate/reference/api-reference#accelerateinvalidate) if you're on a [paid plan](https://www.prisma.io/pricing#accelerate), 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](https://www.prisma.io/pricing). You can manage this via the Accelerate configuration page. -### What is Prisma Postgres's caching layer's consistency model? - -The caching layer in Prisma Postgres 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 Prisma Postgres's cache nodes doesn't propagate to other nodes, so the cache layer by design doesn't need a consistency model. - -Prisma Postgres implements a [read-through caching strategy](https://www.prisma.io/dataguide/managing-databases/introduction-database-caching#read-through) 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](/postgres/database/caching#selecting-a-cache-strategy) for more information on selecting the right cache strategy for your query. ### How is Prisma Postgres's caching layer different from other caching tools, such as Redis? @@ -280,7 +273,7 @@ This global cache feature may not be a good fit for your app if: ### What is the maximum allowed value for the `ttl` parameter when configuring `cacheStrategy`? -The [Time-to-live](/postgres/database/caching#time-to-live-ttl) (`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. +The [Time-to-live](/accelerate/caching) (`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. 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. @@ -314,11 +307,11 @@ Here is a [demo app](https://pris.ly/test-cache-invalidation) to test the time i ### What is on-demand cache invalidation? -[On-demand cache invalidation](/postgres/database/caching#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. +[On-demand cache invalidation](/accelerate/caching) 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. ### When should I use the cache invalidate API? -The [cache invalidate API](/postgres/database/caching#on-demand-cache-invalidation) is essential when data consistency cannot wait for the cache’s standard expiration or revalidation. Key use cases include: +The [cache invalidate API](/accelerate/caching) 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.