Overview
Stringboot’s caching system is designed for maximum performance while minimizing memory usage and network bandwidth. It uses a sophisticated three-layer architecture that automatically manages cache invalidation, eviction, and synchronization.Cache Lookup Flow
When your application requests a string, Stringboot checks three layers in sequence:Application Request
Your app calls
StringProvider.get("key")Layer 1: In-Memory LRU Cache
Fastest access: <1ms
- Size: 1000 entries (configurable)
- Frequency-based prioritization
- Returns immediately if found
Layer 2: Local Database
Fast persistent storage: 5-20ms
- Web
- Android
- iOS
IndexedDB
- Persistent across app restarts
- Automatically synced with memory cache
Layer 3: Network Fetch
Network request: 100-500ms
- String-Sync v2 Protocol
- ETag-based conditional requests
- Delta sync (only changed strings)
- Result cached in Layers 1 & 2 for future requests
99% of requests are served from Layer 1 (memory) with sub-millisecond latency after initial sync
Layer 1: In-Memory Cache
LRU with Access Frequency
The memory cache uses a Least Recently Used (LRU) algorithm enhanced with access frequency tracking:- How It Works
- Configuration
- Performance
- When cache is full (>1000 entries by default)
- Calculate score:
recentAccess * 0.7 + totalAccess * 0.3 - Evict lowest-scoring entries
- Keep frequently and recently accessed strings
Cache Statistics
Monitor cache health with statistics:| Metric | Good | Needs Attention |
|---|---|---|
| Hit Rate | >90% | <80% |
| Memory Usage | 60-80% of max | 100% full |
| Evictions | <100/min | >500/min |
If hit rate is low, consider increasing
cacheSize or preloading frequently accessed strings.Layer 2: Persistent Database
Platform-Specific Storage
- Web - IndexedDB
- Android - Room
- iOS - Core Data
Technology: IndexedDB v2Database Name:
stringboot_cacheObject Stores:strings- Actual string contentmetadata- ETags, timestamps, versioning
- Chrome: ~60% of available disk space
- Firefox: Quota-based, typically 2GB+
- Safari: 1GB default
Soft Deletes
Stringboot uses soft deletes to avoid data loss:- Prevents accidental data loss
- Allows for undo operations
- Maintains referential integrity
- Enables offline delete queuing
Layer 3: Network Sync
String-Sync v2 Protocol
Stringboot uses a custom protocol for efficient synchronization:Step 1: Metadata Check (ETag)
Step 2: Delta Download
Bandwidth Comparison
| Scenario | Traditional | String-Sync v2 | Savings |
|---|---|---|---|
| No changes | 200KB | 2KB | 99% |
| 5 strings changed | 200KB | 10KB | 95% |
| 50 strings changed | 200KB | 80KB | 60% |
| All new (first sync) | 200KB | 200KB | 0% |
ETag checks save 99% bandwidth when content hasn’t changed
Delta sync downloads only what’s needed
Typical monthly bandwidth: 50-200KB vs 3-15MB traditional
Cache Invalidation
When Cache is Cleared
- Automatic
- Manual
- On Errors
- Memory pressure (mobile) - Automatic cleanup
- Storage quota exceeded (web) - Oldest entries removed
- Database corruption - Automatic rebuild
- SDK upgrade - Migration or reset
Cache Warming
Preload strings for instant access:Best Practices
Preload on Start
Preload common strings during app initialization for instant access
Monitor Hit Rate
Aim for >90% cache hit rate. Increase cacheSize if needed.
Don't Force Refresh
Avoid
forceRefresh() unless user explicitly requests itUse Delta Sync
Let SDK handle ETag checks automatically - saves 99% bandwidth
Clear on Logout
Clear cache when user logs out if strings are user-specific
Test Offline
Verify app works perfectly with cached data in airplane mode