Skip to main content

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 in bootstrap.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 server
  • pendingCreate: New entity, waiting to be created on server
  • pendingUpdate: Modified entity, waiting to update on server
  • pendingDelete: Marked for deletion, waiting to delete on server

Implementing Your Sync API

Create a class implementing SyncApiClient:

Cache Configuration

Database Schema

The cache uses SQLite with these tables:
  • wallets: Wallet entities
  • categories: Category entities
  • transactions: Transaction entities
  • generic_cache: Key-value generic cache
  • pending_operations: Retry queue for failed operations

Testing

Use the provided StubSyncApiClient for testing without a backend:

Migration Guide

When the schema changes:
  1. Update _databaseVersion in cache_database.dart
  2. Add migration logic in _onUpgrade
  3. Test migration with existing data