1
0
mirror of https://github.com/Luzifer/badge-gen.git synced 2024-09-19 15:23:04 +00:00
badge-gen/cache/cache.go
Knut Ahlers dc3fc39a2c
Fix linter errors
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2023-09-08 14:23:22 +02:00

35 lines
877 B
Go

// Package cache contains caching implementation for retrieved data
package cache
import (
"net/url"
"time"
"github.com/pkg/errors"
)
// ErrKeyNotFound signalized the key is not present in the cache
var ErrKeyNotFound = errors.New("requested key was not found in database")
// Cache describes an interface used to store generated data
type Cache interface {
Get(namespace, key string) (value string, err error)
Set(namespace, key, value string, ttl time.Duration) (err error)
Delete(namespace, key string) (err error)
}
// GetCacheByURI instantiates a new Cache by the given URI string
func GetCacheByURI(uri string) (Cache, error) {
u, err := url.Parse(uri)
if err != nil {
return nil, errors.Wrap(err, "parsing uri")
}
switch u.Scheme {
case "mem":
return NewInMemCache(), nil
default:
return nil, errors.New("Invalid cache scheme: " + u.Scheme)
}
}