feat:Add Redis Cache Layer for Session History and Statistics Queries - #12
Open
AvAn0sch wants to merge 1 commit into
Open
feat:Add Redis Cache Layer for Session History and Statistics Queries#12AvAn0sch wants to merge 1 commit into
AvAn0sch wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Loading the History and Statistics pages currently takes 10–20 seconds. The root cause is that every query fully deserializes large JSON arrays from
SharedPreferencesand performs filtering and aggregation in memory.This PR introduces a Redis cache layer at the
SessionRepositoryinterface level using the Decorator Pattern, providing caching with zero intrusion into existing business logic.Verification
Successful initialization should produce logs similar to:
Redis Configuration
Configure Redis in Satori\satori_flutter\lib\app\providers.dart:
final redisCacheServiceProvider = Provider((ref) {
final host = Platform.isAndroid ? '10.0.2.2' : 'localhost';
final service = RedisCacheService(
host: host,
port: 6379,
password: null,
);
unawaited(service.initialize());
ref.onDispose(() => service.dispose());
return service;
});
Configuration Parameters
Parameter | Default | Descriptionhost | localhost | Use 10.0.2.2 for Android Emulator; use localhost for iOS Simulator and desktop environments
port | 6379 | Redis server port
password | null | Redis password; leave as null if authentication is not required
ttlSeconds | 600 | Cache expiration time in seconds
Prerequisites
A local Redis instance must be running: