Skip to content

fix(postgrest): keep the cache of a table separate per schema - #1029

Merged
Tr00d merged 1 commit into
masterfrom
fix/postgrest-cache-key-schema
Dec 2, 2026
Merged

Tr00d merged 1 commit into
masterfrom
fix/postgrest-cache-key-schema

Conversation

@Tr00d

@Tr00d Tr00d commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

A table backed by an IPostgrestCacheProvider keyed its cache by the request URL alone, and the URL does not carry the schema, which travels in the Accept-Profile header. The same read of the same table in two schemas therefore shared one cache entry: since WithSchema (#1022), client.WithSchema("archive").Table<Movie>(cache).Get() could be served rows cached for public.movie. The cache is now kept per schema.

Behavior

  • TableWithCache.Get hands CacheBackedRequest a cache scoped to the table's schema: every key it reads or writes is prefixed with that schema (<schema>:<key>).
  • The schema is read from the table's options, so a schema the table resolves later (the upcoming [Table(Schema = ...)]) is picked up with no further change.
  • Keys change for every cached table, so existing cache entries miss once after upgrading; they are refetched and cached under the new key.
  • CacheBackedRequest and its public constructor are unchanged.

Tests

Tier Class Pins
Contract CachedTableSchemaTests A read cached in one schema is not served for the same table in another schema; a second read in the same schema is still a hit

The first test failed before the fix (WasCacheHit was True across schemas).

Diff coverage: 100% (9 lines). Mutation: 2 tested on changed lines (1 killed, 1 timeout), 0 survivors.

Notes

  • The scoped cache's ClearItem and Empty exist only to satisfy IPostgrestCacheProvider; CacheBackedRequest never calls them, so they carry [ExcludeFromCodeCoverage].
  • Scoping through the provider keeps the legacy CacheBackedRequest file untouched; changing it would have brought the whole file under the format bar and its untested members into this fix.

@Tr00d
Tr00d marked this pull request as ready for review December 2, 2026 10:11
@Tr00d
Tr00d merged commit 5706729 into master Dec 2, 2026
11 checks passed
@Tr00d
Tr00d deleted the fix/postgrest-cache-key-schema branch December 2, 2026 10:11
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.

1 participant