Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Don't hash small cache keys with crypto when a plain join works
Prefer a readable deterministic encoding for small nonsensitive cache keys; ensure the encoding is unambiguous before omitting a hash.
Bad example
| 1 | const hash = crypto |
| 2 | .createHash('sha1') |
| 3 | .update([...ids].sort((a, b) => a - b).join(',')) |
| 4 | .digest('hex'); |
| 5 | const cacheKey = `prices-${hash}`; // opaque, slower, harder to inspect |
Explanation (EN)
Hashing a small numeric key can add opacity without improving its identity contract.
Objašnjenje (HR)
Hash malog brojčanog ključa može smanjiti čitljivost bez poboljšanja njegova identiteta.
Good example
| 1 | const cacheKey = `prices:${JSON.stringify([...ids].sort((a, b) => a - b))}`; |
Explanation (EN)
For validated finite numeric IDs, JSON preserves boundaries and sorting canonicalizes order-insensitive requests.
Objašnjenje (HR)
Za validirane konačne brojčane ID-jeve JSON čuva granice vrijednosti, a sortiranje ujednačava zahtjeve kojima redoslijed nije važan.
Notes (EN)
For small nonsensitive cache-key inputs, use a deterministic unambiguous encoding and normalize order only when the result is order-insensitive.
Exceptions / Tradeoffs (EN)
Use a hash when the joined key could exceed the store's key-length limit, or when the raw inputs are sensitive and shouldn't appear in keys/logs. Delimiter joins can collide for arbitrary strings. A plain hash does not hide low-entropy sensitive inputs; follow the cache privacy contract and use a keyed construction where required.
Iznimke / Tradeoffi (HR)
Hash može biti potreban zbog duljine ključa ili osjetljivih ulaza. Spajanje razdjelnikom može stvoriti kolizije za proizvoljne stringove. Obični hash ne skriva lako pogodive osjetljive podatke; slijedi pravila privatnosti cachea i koristi konstrukciju s ključem kada je potrebna.