updateKey method

  1. @override
Future<void> updateKey(
  1. String key,
  2. String newKey
)
override

Renames an existing cache entry from key to newKey.

Throws an exception if the original key is not found.

Implementation

@override
Future<void> updateKey(String key, String newKey) async {
  await _ensureDbOpen();

  final transaction = _db!.transaction('data', 'readwrite');
  final store = transaction.objectStore('data');
  final data = await store.getObject(key);

  if (data == null) {
    await transaction.completed;
    throw Exception('Key not found: $key');
  }

  try {
    await store.put(data, newKey);
    await store.delete(key);
    await transaction.completed;
  } catch (e) {
    transaction.abort();
    rethrow;
  }
}