Skip to main content

Module session_backend

Module session_backend 

Source
Expand description

Pluggable session storage backend.

§What changed vs the original

BeforeAfter
Only save(PersistedSession) + load(): full round-trip for every changeNew update_dc, set_home_dc, update_state allow granular writes
All methods sync (io::Result)New methods are async (optional; default impls fall back to save/load)
No way to update a single DC key without touching everything elseupdate_dc only rewrites what changed

§Backward compatibility

The existing SessionBackend trait is unchanged. The new methods have default implementations that call load → mutate → save, so existing backends (BinaryFileBackend, InMemoryBackend, SqliteBackend, LibSqlBackend) continue to compile and work without modification.

High-performance backends (e.g. a future Redis backend) can override the granular methods to avoid the load/save round-trip.

§Ported from

Session trait (in -session/src/session.rs) exposes:

  • home_dc_id() -> i32 : cheap sync read
  • set_home_dc_id(dc_id) -> BoxFuture<'_, ()> : async write
  • dc_option(dc_id) -> Option<DcOption> : cheap sync read
  • set_dc_option(&DcOption) -> BoxFuture<'_, ()> : async write
  • updates_state() -> BoxFuture<UpdatesState> : async read
  • set_update_state(UpdateState) -> BoxFuture<()>: fine-grained async write

We adopt the same pattern while keeping layer’s PersistedSession struct.

Structs§

BinaryFileBackend
Stores the session in a compact binary file (v2 format).
InMemoryBackend
Ephemeral in-process session: nothing persisted to disk.
SqliteBackendsqlite-session
SQLite-backed session (via rusqlite).
StringSessionBackend
Portable base64 string session backend.

Enums§

UpdateStateChange
A single update-sequence change, applied via SessionBackend::apply_update_state.

Traits§

SessionBackend
Synchronous snapshot backend: saves and loads the full session at once.