snapshot method
Captures the cache, backing store, replacement and in-flight transactions.
External channel peers and already transferred events are not rolled back. Custom replacement policies must implement SnapshotableCacheModelReplacement.
Implementation
CacheModelImage snapshot() {
final policy = replacement;
if (policy is! SnapshotableCacheModelReplacement) {
throw UnsupportedError('Replacement policy does not support snapshots.');
}
if (backingStore.runtimeType != CacheModelBackingStore) {
throw UnsupportedError('Custom backing stores cannot be snapshotted.');
}
final indices = {
for (final (index, txn) in _transactions.indexed) txn: index,
};
return CacheModelImage._(
configuration: _configuration,
portSchemas: [
for (final schema in _portSchemas) cloneTypedPayload(schema)
],
replacementType: policy.runtimeType,
replacementState:
(policy as SnapshotableCacheModelReplacement).snapshotReplacement(),
lines: _lines,
transactions: _transactions,
evictionOffers: [
for (final offers in _evictionOffers)
[for (final txn in offers) indices[txn]!],
],
cycle: _cycle,
backing: backingStore.snapshot(),
serializedRegisters: _serialized?.encodeRegisters(),
);
}