mirror of
https://github.com/grassrootseconomics/eth-tracker.git
synced 2025-02-23 08:02:16 +01:00
* refactor: decouple router to allow adding custom log and input data handlers * feat: refactor handlers * devops: update service build args * chore: cleanup unecessary files/code
44 lines
718 B
Go
44 lines
718 B
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
)
|
|
|
|
type (
|
|
Cache interface {
|
|
Add(context.Context, string) error
|
|
Remove(context.Context, string) error
|
|
Exists(context.Context, string) (bool, error)
|
|
Size(context.Context) (int64, error)
|
|
}
|
|
|
|
CacheOpts struct {
|
|
Logg *slog.Logger
|
|
RedisDSN string
|
|
CacheType string
|
|
}
|
|
)
|
|
|
|
func New(o CacheOpts) (Cache, error) {
|
|
var cache Cache
|
|
|
|
switch o.CacheType {
|
|
case "map":
|
|
cache = NewMapCache()
|
|
case "redis":
|
|
redisCache, err := NewRedisCache(redisOpts{
|
|
DSN: o.RedisDSN,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cache = redisCache
|
|
default:
|
|
cache = NewMapCache()
|
|
o.Logg.Warn("invalid cache type, using default type (map)")
|
|
}
|
|
|
|
return cache, nil
|
|
}
|