Skip to content

feat: Cache results#982

Draft
nutsalhan87 wants to merge 20 commits into
pgdogdev:mainfrom
nutsalhan87:feat/cache
Draft

feat: Cache results#982
nutsalhan87 wants to merge 20 commits into
pgdogdev:mainfrom
nutsalhan87:feat/cache

Conversation

@nutsalhan87
Copy link
Copy Markdown

Issue #859 — Cache Results.

What is done

Caching query results in selected backend. Only non-write queries and queries not in transaction cached. Query parser enabled required.

Cache configured via config file:

[general.cache]
enabled = true
policy = "cache"
ttl = 300

[general.cache.redis]
url = "redis://localhost:6379"
cache_key_prefix = "pgdog:"

Theoretically multiple backends supported because cache storage defined by trait. But implemented only Redis.

There are two policies:

  1. cache — cache all (acceptable to cache) queries by default
  2. no_cache (default) — cache only those queries which have cache hint

Hints are:

  1. cache [ttl = N] — cache this query with provided ttl, or use default ttl from config
  2. force_cache [ttl = N] — force update cache for the query in cache storage
  3. no_cache — do not cache query even if there is "cache" policy

These hints can be provided via query comments (pgdog_cache) or connection parameters (pgdog.cache):

/* pgdog_cache: cache ttl=300 */ SELECT * FROM orders;
SET pgdog.cache = 'no_cache';
psql postgresql://postgres:postgres@127.0.0.1:5432/postgres?options=-c%20pgdog.cache%3Dcache

And many more in docs/CACHE.md.

What is not done

  1. Tests in any kind: unit, integration, stress

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 18, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants