Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP2universalStack: TypeScript
cachingdrymagic-numbersmaintainability
Centralize cache-key computation and TTL constants in one place
Let the caching layer compute the key (so the hashing strategy lives in one spot) and define TTLs as named, semantic constants rather than scattering raw numbers across call sites.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | this.cache.set(this.cacheKey(url), data, 300); // raw 300 everywhere |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | enum CacheTtl { LiveVideo = 300 } |
| 2 | this.cache.set(url, data, CacheTtl.LiveVideo); // key computed inside cache |
Explanation (EN)
Objašnjenje (HR)