cache.go 430 B

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