feat: v0.12.0 — live device cache (_LiveCache) in sfm/server.py

Ports the intelligent-caching branch concept to a plain Python in-memory
implementation — no SQLAlchemy, no extra DB table, no new dependencies.

_LiveCache (threading.Lock + dicts) caches:
  - device info: indefinite, invalidated by POST /device/config
  - events: keyed by (conn_key, device_event_count); count-probe fast path
    (~2s poll+count_events) avoids full downloads when nothing is new
  - monitor status: 30-second TTL, invalidated by monitor start/stop
  - waveforms: permanent per (conn_key, event_index)

All four cached endpoints accept ?force=true to bypass the cache.
Removes sfm/cache.py (SQLAlchemy experiment, now superseded).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 15:57:02 -04:00
committed by serversdown
parent 7883a31aa7
commit 5591d345d9
3 changed files with 194 additions and 11 deletions
+35
View File
@@ -4,6 +4,41 @@ All notable changes to seismo-relay are documented here.
---
## v0.12.0 — 2026-04-13
### Added
- **`sfm/server.py``_LiveCache`** — in-memory live device cache, eliminating
redundant TCP round-trips between requests. No extra dependencies (plain Python
dict + threading.Lock). Replaces the SQLAlchemy-based `sfm/cache.py` experiment
from the `feature/intelligent-caching` branch.
Cache behaviour by endpoint:
| Endpoint | Cache strategy |
|---|---|
| `GET /device/info` | Indefinite; invalidated by `POST /device/config` |
| `GET /device/events` | Count-probe fast path: quick `poll()+count_events()` (~2s); return cache if count matches; full download only when new events detected |
| `GET /device/monitor/status` | 30-second TTL; invalidated by monitor start/stop |
| `GET /device/event/{idx}/waveform` | Permanent per-index (waveforms are immutable) |
- **`?force=true` param** on all four cached endpoints — bypasses cache and re-reads
from device.
- **`POST /device/config` cache invalidation** — marks device info + events dirty so
the next read reflects the new compliance config.
- **`POST /device/monitor/start` / `stop` cache invalidation** — evicts the monitor
status cache entry immediately so the next poll returns the updated state.
### Removed
- `sfm/cache.py` — SQLAlchemy-based cache from the experimental caching branch.
Its logic has been ported to the sqlite3-native `_LiveCache` class above.
`sqlalchemy` is no longer a dependency.
---
## v0.11.0 — 2026-04-13
### Added