Documentation
¶
Overview ¶
Package postgres is a cache.Cache backed by a Postgres table, for apps that want a shared cache without running Redis. Entries expire by TTL; Sweep removes the dead rows.
Index ¶
- func SchemaSQL() string
- type Cache
- func (c *Cache) Delete(ctx context.Context, key string) error
- func (c *Cache) Describe() cache.Description
- func (c *Cache) Get(ctx context.Context, key string) ([]byte, bool, error)
- func (c *Cache) Set(ctx context.Context, key string, val []byte, ttl time.Duration) error
- func (c *Cache) Sweep(ctx context.Context) (int64, error)
- type DB
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a Postgres-backed cache.Cache.
func New ¶
New returns a Cache over db, usually a *pgxpool.Pool. Create the table with SchemaSQL first. It does no I/O.
func (*Cache) Describe ¶
func (c *Cache) Describe() cache.Description
Describe implements cache.Cache.
type DB ¶
type DB interface {
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}
DB is the subset of *pgxpool.Pool (and pgx.Conn, pgx.Tx) the cache uses.