isCacheNewer
isCacheNewer(
cached,incoming):boolean
Defined in: packages/ddd-core/persistence/helpers/cache-version.helper.ts:32
Checks whether a cached snapshot or record is strictly newer than an incoming record based on explicit version numbers, generation counters, or updatedAt timestamps.
Returns true only if cached is strictly newer than incoming.
Returns false if incoming is newer, equal, or if no meaningful ordering can be determined.
Comparison precedence:
- CacheMutationBarrier: a barrier outranks any snapshot. A cached
barrier is newer than an incoming snapshot, an incoming barrier always
replaces a cached snapshot, and between two barriers the cached one is
newer unless the incoming one has a later
createdAt. - Numeric
version(optimistic concurrency version) - Numeric
__gen(generation sequence counter) updatedAt(Date instance or ISO 8601 string / timestamp)
Parameters
Section titled “Parameters”cached
Section titled “cached”unknown
The existing data in cache.
incoming
Section titled “incoming”unknown
The incoming data being written or compared.
Returns
Section titled “Returns”boolean
true if cached is strictly newer than incoming, false otherwise.
Example
Section titled “Example”Comparing versioned aggregate snapshots
isCacheNewer({ id: '1', version: 3 }, { id: '1', version: 2 }); // trueisCacheNewer({ id: '1', version: 2 }, { id: '1', version: 3 }); // falseisCacheNewer({ id: '1', version: 2 }, { id: '1', version: 2 }); // false