Skip to content

fix: upsert cache entries to prevent unique constraint errors#126

Merged
trijpstra-fourlights merged 3 commits intomainfrom
fix/harden-cache-upsert
Jan 8, 2026
Merged

fix: upsert cache entries to prevent unique constraint errors#126
trijpstra-fourlights merged 3 commits intomainfrom
fix/harden-cache-upsert

Conversation

@trijpstra-fourlights
Copy link
Contributor

Fixes #115

Changed the cache entry save strategy from find-first-then-update-or-create to create-first-then-handle-unique-violation. This approach better handles concurrent requests where multiple instances might attempt to create the same cache entry simultaneously. By catching unique constraint violations and falling back to find-and-update, we prevent duplicate entries and ensure data consistency while maintaining the original caching behavior.
Create a database-agnostic utility function to detect unique constraint
violations across PostgreSQL, MySQL, SQLite, and SQL Server. This
improves the reliability of the cache upsert logic by properly handling
database-specific error codes and numbers.
@trijpstra-fourlights trijpstra-fourlights merged commit fb5c117 into main Jan 8, 2026
2 checks passed
@trijpstra-fourlights trijpstra-fourlights deleted the fix/harden-cache-upsert branch January 8, 2026 13:44
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.

Cache saving can fail due to race-condition resulting in multiple inserts on the same hash-key

1 participant