instance.go 654 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package cache
  2. import (
  3. "context"
  4. "time"
  5. )
  6. var (
  7. std Cache
  8. )
  9. func init() {
  10. std = NewMemCache()
  11. }
  12. func SetCache(l Cache) {
  13. std = l
  14. }
  15. func GetCache() Cache {
  16. return std
  17. }
  18. func Set(ctx context.Context, key string, value any) {
  19. std.Set(ctx, key, value)
  20. }
  21. func SetEx(ctx context.Context, key string, value any, expire time.Duration) {
  22. std.SetEx(ctx, key, value, expire)
  23. }
  24. func Try(ctx context.Context, key string, cb LoadFunc) (value any, err error) {
  25. return std.Try(ctx, key, cb)
  26. }
  27. func Get(ctx context.Context, key string) (value any, ok bool) {
  28. return std.Get(ctx, key)
  29. }
  30. func Del(ctx context.Context, key string) {
  31. std.Del(ctx, key)
  32. }