Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Derive cache keys from all inputs that affect the result
Build cache keys from every parameter that changes the response, not a fixed string, to avoid cache collisions across filters.
Bad example
| 1 | async getOrders(params?: OrderQuery) { |
| 2 | const cacheKey = 'orders'; |
| 3 | const cached = await this.cache.get(cacheKey); |
| 4 | if (cached) return cached; |
| 5 | const result = await this.fetchOrders(params); |
| 6 | await this.cache.set(cacheKey, result, TTL); |
| 7 | return result; |
| 8 | } |
Explanation (EN)
A fixed or incomplete key can return another request variant's data.
Objašnjenje (HR)
Fiksni ili nepotpuni ključ može vratiti podatke druge varijante zahtjeva.
Good example
| 1 | async getOrders(params?: OrderQuery) { |
| 2 | const cacheKey = `orders-${params?.country ?? 'all'}`; |
| 3 | const cached = await this.cache.get(cacheKey); |
| 4 | if (cached) return cached; |
| 5 | const result = await this.fetchOrders(params); |
| 6 | await this.cache.set(cacheKey, result, TTL); |
| 7 | return result; |
| 8 | } |
Explanation (EN)
Encoding the filtering params into the key isolates each variant, so different filters never read each other's cached results.
Objašnjenje (HR)
Ugrađivanje parametara filtriranja u ključ izolira svaku varijantu, pa različiti filteri nikad ne čitaju tuđe cachirane rezultate.
Notes (EN)
Include every response-shaping input in the key, including validated query/body parameters, tenant/authorization scope, locale and relevant schema version.
Bilješke (HR)
U ključ uključi svaki ulaz koji oblikuje odgovor: validirane parametre upita i tijela, tenant i autorizacijski opseg, jezik te relevantnu verziju sheme.
Exceptions / Tradeoffs (EN)
Normalize only semantically equivalent inputs and avoid exposing credentials or sensitive raw values. A default sentinel must not collide with a valid supplied value.