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 ruleP2stack specificStack: TypeScript
cachingdryreadability
Use the cache wrap/memoize helper instead of manual get/set
Prefer a `cache.wrap(key, producer, opts)` helper that returns cached value or computes-and-stores, over hand-written get-check-set-return blocks.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const cached = cache.get(key); |
| 2 | if (cached) return cached; |
| 3 | const data = await fetchData(); |
| 4 | cache.set(key, data, ttl); |
| 5 | return data; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | return cache.wrap(key, () => fetchData(), { ttl }); |
Explanation (EN)
Objašnjenje (HR)