feat: implement hybrid cache store with singleflight
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:social_app/core/cache/hybrid_cache_store.dart';
|
||||
import 'package:social_app/core/cache/memory_cache_store.dart';
|
||||
import 'package:social_app/core/cache/persistent_cache_store.dart';
|
||||
|
||||
void main() {
|
||||
test('same key concurrent load should execute loader once', () async {
|
||||
var calls = 0;
|
||||
final store = HybridCacheStore(
|
||||
memory: MemoryCacheStore(),
|
||||
persistent: PersistentCacheStore(),
|
||||
);
|
||||
|
||||
Future<String> loader() async {
|
||||
calls += 1;
|
||||
await Future<void>.delayed(const Duration(milliseconds: 20));
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
await Future.wait([
|
||||
store.getOrLoad<String>('k', loader: loader),
|
||||
store.getOrLoad<String>('k', loader: loader),
|
||||
]);
|
||||
|
||||
expect(calls, 1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user