feat: 重构 Reminder Notification 系统并更新应用包名
This commit is contained in:
Vendored
+25
@@ -39,6 +39,10 @@ class MemoryCacheStore implements CacheStore {
|
||||
Future<void> remove(String key) async {
|
||||
_values.remove(key);
|
||||
}
|
||||
|
||||
Future<void> removeByPrefix(String prefix) async {
|
||||
_values.removeWhere((key, _) => key.startsWith(prefix));
|
||||
}
|
||||
}
|
||||
|
||||
class SharedPrefsCacheStore implements CacheStore {
|
||||
@@ -135,6 +139,18 @@ class PersistentCacheStore implements CacheStore {
|
||||
final store = SharedPrefsCacheStore(prefs: prefs);
|
||||
await store.remove(key);
|
||||
}
|
||||
|
||||
Future<void> removeByPrefix(String prefix) async {
|
||||
final prefs = await _getPrefs();
|
||||
if (prefs == null) {
|
||||
_fallbackValues.removeWhere((key, _) => key.startsWith(prefix));
|
||||
return;
|
||||
}
|
||||
final targets = prefs.getKeys().where((key) => key.startsWith(prefix));
|
||||
for (final key in targets) {
|
||||
await prefs.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class HybridCacheStore {
|
||||
@@ -166,6 +182,15 @@ class HybridCacheStore {
|
||||
await persistent.remove(key);
|
||||
}
|
||||
|
||||
Future<void> clearByPrefix(String prefix) async {
|
||||
if (memory is MemoryCacheStore) {
|
||||
await (memory as MemoryCacheStore).removeByPrefix(prefix);
|
||||
}
|
||||
if (persistent is PersistentCacheStore) {
|
||||
await (persistent as PersistentCacheStore).removeByPrefix(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
Future<T> getOrLoad<T>(String key, {required Future<T> Function() loader}) {
|
||||
final running = _inflight[key];
|
||||
if (running != null) {
|
||||
|
||||
Reference in New Issue
Block a user