instance.go 541 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 Get(ctx context.Context, key string) (value any, ok bool) {
  25. return std.Get(ctx, key)
  26. }
  27. func Del(ctx context.Context, key string) {
  28. std.Del(ctx, key)
  29. }