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
| Field | Type | Description |
|---|---|---|
id | String | Local UUID (primary key) |
serverId | String? | Server-assigned ID after sync |
name | String | Wallet name |
currency | String | Currency code (default: USD) |
balance | double | Current balance |
isDeleted | bool | Soft delete flag |
syncStatus | SyncStatus | sync state |
createdAt | DateTime | Creation timestamp |
updatedAt | DateTime | Last update timestamp |
syncedAt | DateTime? | Last successful sync |
Category
| Field | Type | Description |
|---|---|---|
id | String | Local UUID |
serverId | String? | Server ID after sync |
name | String | Category name |
type | String | ’income’ or ‘expense’ |
color | int? | Color value |
icon | String? | Icon identifier |
isDeleted | bool | Soft delete flag |
syncStatus | SyncStatus | Sync state |
Transaction
| Field | Type | Description |
|---|---|---|
id | String | Local UUID |
serverId | String? | Server ID after sync |
walletId | String | Reference to wallet |
categoryId | String? | Reference to category |
amount | double | Transaction amount |
type | String | ’income’, ‘expense’, or ‘transfer’ |
description | String? | Optional description |
date | DateTime | Transaction date |
isDeleted | bool | Soft delete flag |
syncStatus | SyncStatus | Sync state |
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

