Skip to content

Commit c9ad730

Browse files
docs: explain caching
1 parent 4edc187 commit c9ad730

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ LIMIT 200;
111111
> removed, then PostgreSQL may not [push down the condition](https://wiki.postgresql.org/wiki/Inlining_of_SQL_functions),
112112
> causing all pages to be requested and buffered.
113113
114+
## Caching
115+
116+
Sending requests to the Stripe API for every SQL query can be slow. Combine [materialized views](https://www.postgresql.org/docs/current/rules-materializedviews.html) with [`pg_cron`](https://github.com/citusdata/pg_cron) for scheduled data pulls:
117+
118+
```sql
119+
CREATE MATERIALIZED VIEW stripe_coupons AS
120+
SELECT *
121+
FROM stripe_coupons.list();
122+
123+
-- Refresh the view every 4 hours.
124+
SELECT cron.schedule(
125+
'refresh-stripe-coupons',
126+
'0 */4 * * *',
127+
'REFRESH MATERIALIZED VIEW CONCURRENTLY stripe_coupons'
128+
);
129+
```
130+
114131
## Troubleshooting
115132

116133
### Installation

0 commit comments

Comments
 (0)