Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Set cache TTL to match how often the data actually changes
Choose cache lifetime from actual mutability and the allowed staleness. Historical dates alone do not make data immutable, and rarely changing assets should not be needlessly refetched.
Bad example
| 1 | const ttlSeconds = report.date < today ? 86400 : 30; |
| 2 | await cache.set(key, report, { ttl: ttlSeconds }); |
Explanation (EN)
An earlier date can still be revised. A fixed long lifetime ignores the allowed staleness and available invalidation.
Objašnjenje (HR)
Podaci za raniji datum mogu se naknadno promijeniti. Dugo trajanje zanemaruje dopuštenu zastarjelost i dostupnu invalidaciju.
Good example
| 1 | const policy = freshnessPolicies[report.kind]; |
| 2 | const ttlSeconds = Math.min(policy.refreshIntervalSeconds, policy.maxStalenessSeconds); |
| 3 | await cache.set(key, report, { ttl: ttlSeconds }); |
Explanation (EN)
A domain policy explicitly bounds freshness for mutable records. Revision events can additionally invalidate affected keys.
Objašnjenje (HR)
Pravila domene izričito ograničavaju zastarjelost promjenjivih zapisa. Događaji izmjene mogu dodatno poništiti pogođene ključeve.
Notes (EN)
Apply this when selecting or reviewing cache lifetimes. Check whether past records can be corrected, reprocessed or adjusted after publication. Bound stale data by the domain allowance, account for upstream age and consider event-driven invalidation. A lower TTL mitigates staleness but does not prove records are final. Conversely, avoid a very short lifetime for stable assets without a freshness need.
Bilješke (HR)
Primijeni pri odabiru ili provjeri trajanja cachea. Provjeri mogu li se raniji zapisi naknadno ispraviti, ponovno obraditi ili prilagoditi. Ograniči zastarjelost prema pravilima domene, uzmi u obzir starost izvornog podatka i razmotri invalidaciju na događaj izmjene. Kraće trajanje ublažava zastarjelost, ali ne dokazuje konačnost zapisa. Stabilnim resursima bez potrebe za svježinom nemoj nepotrebno skratiti trajanje.
Exceptions / Tradeoffs (EN)
Immutable versioned snapshots may use long lifetimes. A documented bounded delay can be acceptable when invalidation is unavailable. Choose the actual value from domain evidence, not the illustrative example or a universal one-hour rule.
Iznimke / Tradeoffi (HR)
Nepromjenjive verzionirane snimke mogu imati dugo trajanje. Dokumentirano ograničeno kašnjenje može biti prihvatljivo kad invalidacija nije dostupna. Stvarnu vrijednost odaberi prema dokazima domene, a ne primjeru ili univerzalnom pravilu jednog sata.