You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hyperdrive automatically caches the most popular queries executed against your database, reducing the need to go back to your database (incurring latency and database load) for every query.
9
11
10
12
## What does Hyperdrive cache?
@@ -15,22 +17,47 @@ Besides determining the difference between a `SELECT` and an `INSERT`, Hyperdriv
15
17
16
18
For example, a read query that populates the front page of a news site would be cached:
17
19
18
-
```sql
19
-
-- Cacheable
20
-
SELECT*FROM articles
21
-
WHEREDATE(published_time) =CURRENT_DATE()
22
-
ORDER BY published_time DESC
23
-
LIMIT50
24
-
```
20
+
<Tabs>
21
+
<TabItemlabel="PostgreSQL">
22
+
```sql
23
+
-- Cacheable
24
+
SELECT*FROM articles
25
+
WHEREDATE(published_time) =CURRENT_DATE()
26
+
ORDER BY published_time DESC
27
+
LIMIT50
28
+
```
29
+
</TabItem>
30
+
<TabItemlabel="MySQL">
31
+
```sql
32
+
-- Cacheable
33
+
SELECT*FROM articles
34
+
WHEREDATE(published_time) = CURDATE()
35
+
ORDER BY published_time DESC
36
+
LIMIT50
37
+
```
38
+
</TabItem>
39
+
</Tabs>
25
40
26
41
Mutating queries (including `INSERT`, `UPSERT`, or `CREATE TABLE`) and queries that use [functions designated as `volatile` by PostgreSQL](https://www.postgresql.org/docs/current/xfunc-volatility.html) are not cached:
27
42
28
-
```sql
29
-
-- Not cached
30
-
INSERT INTO users(id, name, email) VALUES(555, 'Matt', '[email protected]');
31
-
32
-
SELECT LASTVAL(), *FROM articles LIMIT50;
33
-
```
43
+
<Tabs>
44
+
<TabItemlabel="PostgreSQL">
45
+
```sql
46
+
-- Not cached
47
+
INSERT INTO users(id, name, email) VALUES(555, 'Matt', '[email protected]');
48
+
49
+
SELECT LASTVAL(), *FROM articles LIMIT50;
50
+
```
51
+
</TabItem>
52
+
<TabItemlabel="MySQL">
53
+
```sql
54
+
-- Not cached
55
+
INSERT INTO users(id, name, email) VALUES(555, 'Thomas', '[email protected]');
You can also configure multiple Hyperdrive connections from a single application: one connection that enables caching for popular queries, and a second connection where you do not want to cache queries, but still benefit from Hyperdrive's latency benefits and connection pooling.
60
87
61
-
For example, using the [Postgres.js](/hyperdrive/configuration/connect-to-postgres/) driver:
0 commit comments