Overview
The Flutter cache layer provides a local-first, offline-capable caching system with automatic synchronization. It uses SQLite for persistent storage on mobile devices and supports soft deletes with deferred hard deletion until after server sync.Features
- Generic Cache: Key-value storage with optional TTL
- Entity Caching: Typed repositories for Wallet, Category, and Transaction
- Offline-First: Works without network, queues changes for sync
- Soft Deletes: Entities are marked deleted, hard deleted only after sync
- Auto-Sync: Automatically syncs pending changes on app startup
- LRU Eviction: Configurable cache size with automatic eviction
Architecture
Quick Start
Initialize
The cache is automatically initialized inbootstrap.dart:
Using the Cache
Querying Entities
Deleting Entities
Manual Sync
Data Models
Wallet
Category
Transaction
Sync Status
Entities have one of four sync states:synced: Entity is in sync with serverpendingCreate: New entity, waiting to be created on serverpendingUpdate: Modified entity, waiting to update on serverpendingDelete: Marked for deletion, waiting to delete on server
Implementing Your Sync API
Create a class implementingSyncApiClient:
Cache Configuration
Database Schema
The cache uses SQLite with these tables:wallets: Wallet entitiescategories: Category entitiestransactions: Transaction entitiesgeneric_cache: Key-value generic cachepending_operations: Retry queue for failed operations
Testing
Use the providedStubSyncApiClient for testing without a backend:
Migration Guide
When the schema changes:- Update
_databaseVersionincache_database.dart - Add migration logic in
_onUpgrade - Test migration with existing data

