fix: Delete in transaction on new store does not clear cache correctly
This commit is contained in:
parent
af9006a278
commit
40565464e0
|
|
@ -166,7 +166,10 @@ class Box<V> {
|
||||||
txn ??= boxCollection._db.transaction(name, 'readwrite');
|
txn ??= boxCollection._db.transaction(name, 'readwrite');
|
||||||
final store = txn.objectStore(name);
|
final store = txn.objectStore(name);
|
||||||
await store.delete(key);
|
await store.delete(key);
|
||||||
_cache.remove(key);
|
|
||||||
|
// Set to null instead remove() so that inside of transactions null is
|
||||||
|
// returned.
|
||||||
|
_cache[key] = null;
|
||||||
_cachedKeys?.remove(key);
|
_cachedKeys?.remove(key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +186,7 @@ class Box<V> {
|
||||||
final store = txn.objectStore(name);
|
final store = txn.objectStore(name);
|
||||||
for (final key in keys) {
|
for (final key in keys) {
|
||||||
await store.delete(key);
|
await store.delete(key);
|
||||||
_cache.remove(key);
|
_cache[key] = null;
|
||||||
_cachedKeys?.remove(key);
|
_cachedKeys?.remove(key);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -302,7 +302,9 @@ class Box<V> {
|
||||||
txn.delete(name, where: 'k = ?', whereArgs: [key]);
|
txn.delete(name, where: 'k = ?', whereArgs: [key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
_cache.remove(key);
|
// Set to null instead remove() so that inside of transactions null is
|
||||||
|
// returned.
|
||||||
|
_cache[key] = null;
|
||||||
_cachedKeys?.remove(key);
|
_cachedKeys?.remove(key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -326,7 +328,7 @@ class Box<V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final key in keys) {
|
for (final key in keys) {
|
||||||
_cache.remove(key);
|
_cache[key] = null;
|
||||||
_cachedKeys?.removeAll(keys);
|
_cachedKeys?.removeAll(keys);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,18 @@ void main() {
|
||||||
await box.clear();
|
await box.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Box.delete in transaction', () async {
|
||||||
|
final box = collection.openBox<Map>('cats');
|
||||||
|
await box.put('fluffy', data);
|
||||||
|
await box.put('loki', data2);
|
||||||
|
await collection.transaction(() async {
|
||||||
|
await box.delete('fluffy');
|
||||||
|
expect(await box.get('fluffy'), null);
|
||||||
|
});
|
||||||
|
expect(await box.get('fluffy'), null);
|
||||||
|
await box.clear();
|
||||||
|
});
|
||||||
|
|
||||||
test('Box.deleteAll', () async {
|
test('Box.deleteAll', () async {
|
||||||
final box = collection.openBox<Map>('cats');
|
final box = collection.openBox<Map>('cats');
|
||||||
await box.put('fluffy', data);
|
await box.put('fluffy', data);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue