Skip to content

EN Storage and Cache

Andrewkydev edited this page Aug 25, 2026 · 1 revision

Storage and Cache

Русский: RU-Storage-and-Cache

storage.Store combines the Users, Chats, and Sessions repositories.

Memory

store := memory.New()
app.Storage(store)

Suitable for tests and ephemeral processes. All data is lost after a restart.

PostgreSQL

store, err := postgres.New(ctx, os.Getenv("ASTRAENGINE_DATABASE_URL"))
if err != nil {
	return err
}
defer store.Close()

if err := store.EnsureSchema(ctx); err != nil {
	return err
}
app.Storage(store)

postgres.New creates a pool, but not the schema. Call EnsureSchema explicitly or replace it with your own migration system.

Sessions

repo := app.Store().Sessions()
err := repo.Set(ctx, "verification:42", []byte(`{"step":1}`), 15*time.Minute)
value, err := repo.Get(ctx, "verification:42")
err = repo.Delete(ctx, "verification:42")

A missing or expired entry is compatible with storage.ErrNotFound. The repository stores opaque bytes; their structure is defined by the consumer. state serializes sessions automatically.

Calling app.Storage(store) does not persist incoming users or chats by itself; application middleware or a module must do that.

Cache

cache/memory and cache/nop are available with Get, Set, Delete, and Remember operations. There is no Redis implementation yet.

Clone this wiki locally