Documentation
¶
Overview ¶
Package database caches bytes in PostgreSQL or MySQL through a caller-owned Bun DB. Apply the central cache_entries migration before use; constructors never run DDL.
Index ¶
- type Config
- type Store
- func (s *Store) Clear(ctx context.Context) error
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Exists(ctx context.Context, key string) (bool, error)
- func (s *Store) Get(ctx context.Context, key string) ([]byte, bool, error)
- func (s *Store) GetMulti(ctx context.Context, keys []string) (map[string][]byte, error)
- func (s *Store) PruneExpired(ctx context.Context, limit int) (int64, error)
- func (s *Store) Remember(ctx context.Context, key string, ttl time.Duration, ...) (any, error)
- func (s *Store) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (s *Store) SetMulti(ctx context.Context, items map[string][]byte, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store borrows DB and never closes it. Cache operations join the transaction in ctx through pkg/database.Executor. Construct once; safe for concurrent use.
func (*Store) Clear ¶
Clear deletes this namespace through the caller's transaction executor. It does not drop tables or close the shared database pool.
func (*Store) PruneExpired ¶
PruneExpired deletes at most limit expired rows in this namespace (1–10000). Call periodically outside business transactions. It uses a separate, bounded READ COMMITTED transaction, skips locked rows and never deletes a refreshed row. Expired values are already misses even if this cleanup has not run.
func (*Store) Remember ¶
func (s *Store) Remember(ctx context.Context, key string, ttl time.Duration, load func(context.Context) (any, error)) (any, error)
Remember returns a cached JSON value or loads it on a miss. See cache.Remember for validation, error, expiry and concurrent-loading semantics.