feat(cache): Add lightweight in-memory cache with TTL and LRU eviction

This commit is contained in:
cogwheel0
2025-11-22 21:53:14 +05:30
parent 8ed75f8f14
commit c4a36bb51c
14 changed files with 1298 additions and 242 deletions

View File

@@ -0,0 +1,35 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../persistence/persistence_providers.dart';
import '../services/optimized_storage_service.dart';
import '../services/worker_manager.dart';
/// Provides a shared [FlutterSecureStorage] instance with platform-specific
/// configuration.
final secureStorageProvider = Provider<FlutterSecureStorage>((ref) {
return const FlutterSecureStorage(
aOptions: AndroidOptions(
encryptedSharedPreferences: true,
sharedPreferencesName: 'conduit_secure_prefs',
preferencesKeyPrefix: 'conduit_',
// Avoid auto-wipe on transient errors; handled at call sites instead.
resetOnError: false,
),
iOptions: IOSOptions(
accountName: 'conduit_secure_storage',
synchronizable: false,
),
);
});
/// Optimized storage service backed by Hive plus secure storage.
final optimizedStorageServiceProvider = Provider<OptimizedStorageService>((
ref,
) {
return OptimizedStorageService(
secureStorage: ref.watch(secureStorageProvider),
boxes: ref.watch(hiveBoxesProvider),
workerManager: ref.watch(workerManagerProvider),
);
});