Repository navigation
RU Storage and Cache
Andrewkydev edited this page Aug 25, 2026
·
1 revision
English: EN-Storage-and-Cache
storage.Store объединяет Users, Chats и Sessions repositories.
store := memory.New()
app.Storage(store)Подходит для тестов и ephemeral процессов. После рестарта данные исчезают.
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 создаёт pool, но не schema. EnsureSchema нужно вызвать явно или заменить собственной migration системой.
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")Отсутствующая или истёкшая запись совместима с storage.ErrNotFound. Repository хранит opaque bytes; структуру определяет потребитель. state сериализует session автоматически.
app.Storage(store) сам по себе не записывает входящих users/chats — это делает application middleware или модуль.
Доступны cache/memory и cache/nop с операциями Get, Set, Delete, Remember. Redis implementation пока отсутствует.