# Caching Queries (/cache/cache) import { Callout } from 'fumadocs-ui/components/callout' Once your application is sending SQL queries through Readyset Cache, you can see which queries are cacheable. **Deep caches can be created only once all tables have finished the initial snapshotting process.** Snapshotting and replication are only required for **deep caches**, which incrementally maintain query results from your database's replication stream. **Shallow caches** are TTL-based and served without a snapshot, so they do not depend on snapshotting progress. See [Deep Caching](/concepts/deep-caching) and [Shallow Caching](/concepts/shallow-caching) for the difference. Before attempting to create a deep cache, check Readyset Cache's overall snapshotting progress by connecting a SQL shell to Readyset Cache and running the following custom SQL command: ```sql SHOW READYSET STATUS; ``` Look for the row labeled `Snapshot Status` -- it should be either `In Progress` or `Completed`. ```text name | value ----------------+---------- Snapshot Status | Completed (1 row) ``` Once you see the status is `Completed` Readyset Cache is ready to cache queries. If Readyset restarts during the initial snapshot, tables whose snapshot already completed are not re-snapshotted; only tables that were still being snapshotted restart from the beginning. See [Snapshotting](/reference/snapshots). If you are unsure what queries to cache, you can [run diagnostics with both Postgres and MySQL](/reference/profiling-queries) to ascertain costly queries. ## 1. Creating a Cache It's important to note that Readyset Cache sits between your application and your database. SQL traffic must pass through Readyset Cache so that it can cache desired queries. You can check to see that an application is successfully connected to Readyset Cache by using the Readyset Cache shell and running the commands `show proxied queries` (you should see queries) or `show connections` (you should see two connections - one being you in the Readyset Cache shell and the other being your application). Once you've [identified queries](/reference/profiling-queries) that can benefit from caching with Readyset Cache, use Readyset Cache's custom SQL commands to check if the queries are supported and then to cache supported queries in Readyset Cache. ## 2. Checking query support To view all queries that Readyset Cache has proxied to the upstream database and check if they can be cached in Readyset Cache, connect to Readyset Cache via the shell and run: ```sql SHOW PROXIED QUERIES; ``` This command returns a virtual table with four columns: * **QueryID:** A unique identifier for the query. * **Proxied Query:** The text of the query being proxied. * **Readyset Cache supported:** Whether or not Readyset Cache can cache the query. * If the value is `pending`, check again until you see `yes` or `no`. If the value remains pending for more than 15 seconds, the query is unsupported. * If the value is `yes`, Readyset Cache can cache the query. * If the value is `no`, Readyset Cache cannot cache the query. * **Count:** The number of times Readyset Cache has seen this query. To successfully cache the results of a query, Readyset Cache must support the SQL features and syntax in the query. For more details, see [SQL Support](/concepts/deep-caching/supported-data-types) . ​If an unsupported feature is important to your use case, [submit a feature request](https://github.com/readysettech/readyset/issues/new/choose) . ## 3. Cache queries Readyset Cache supports two kinds of caches: * **Deep caches** use streaming dataflow to incrementally maintain query results from your database's replication stream, so cached results stay up to date automatically. They require the initial snapshot to be complete. See [Deep Caching](/concepts/deep-caching). * **Shallow caches** are TTL-based: they store query results in memory and serve them until they expire, without building a materialized view. They support a broader range of queries and do not depend on snapshotting. See [Shallow Caching](/concepts/shallow-caching). ### Deep caches To create a deep cache, use: ```sql CREATE DEEP CACHE [] [WITH (