restore method
- CacheModelImage image
Atomically restores a compatible full image.
Callers must also restore or coordinate external channel peers.
Implementation
void restore(CacheModelImage image) {
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 restored.');
}
if (image._configuration != _configuration ||
!samePayloadSchemas(image._portSchemas, _portSchemas) ||
image._replacementType != policy.runtimeType) {
throw ArgumentError('Cache image configuration does not match.');
}
backingStore._validateImage(image.backing);
final commitRegisters = _serialized?.decodeRegisters(
image._serializedRegisters ??
(throw ArgumentError('Cache image has no serialized state.')));
final snapshotPolicy = policy as SnapshotableCacheModelReplacement;
final restored = [for (final txn in image._transactions) txn.copy()];
snapshotPolicy
..validateSnapshot(image._replacementState)
..restoreSnapshot(image._replacementState);
backingStore.load(image.backing, replace: true);
for (final (index, ways) in image._lines.indexed) {
_lines[index].setAll(0, ways);
}
_transactions
..clear()
..addAll(restored);
for (final (index, offers) in image._evictionOffers.indexed) {
_evictionOffers[index]
..clear()
..addAll(offers.map((txn) => restored[txn]));
}
_cycle = image._cycle;
commitRegisters?.call();
_refresh();
}