cache.go 423 B

123456789101112131415161718
  1. package cache
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type (
  7. LoadFunc func(ctx context.Context) (any, error)
  8. )
  9. type Cache interface {
  10. Set(ctx context.Context, key string, value any)
  11. SetEx(ctx context.Context, key string, value any, expire time.Duration)
  12. Get(ctx context.Context, key string) (value any, ok bool)
  13. Try(ctx context.Context, key string, cb LoadFunc) (value any, err error)
  14. Del(ctx context.Context, key string)
  15. }