2021-11-16 04:56:33 +00:00
|
|
|
package cheapcash
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2021-11-16 05:20:12 +00:00
|
|
|
"strings"
|
2021-11-16 04:56:33 +00:00
|
|
|
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Cache struct {
|
|
|
|
sync.Mutex
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
|
|
|
var ErrNotExists = errors.New("key does not exist")
|
|
|
|
var ErrInvalidPath = errors.New("path supplied is invalid")
|
|
|
|
var ErrDiskFull = errors.New("there was no space left on the device")
|
2021-11-16 13:18:23 +00:00
|
|
|
var ErrExists = errors.New("key already exists")
|
2021-11-16 04:56:33 +00:00
|
|
|
|
|
|
|
func Default() *Cache {
|
|
|
|
return &Cache{
|
|
|
|
Path: "/tmp/cheapcash/",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(path string) *Cache {
|
2021-11-16 05:20:12 +00:00
|
|
|
if !strings.HasSuffix(path, "/") {
|
|
|
|
path += "/"
|
|
|
|
}
|
|
|
|
|
2021-11-16 04:56:33 +00:00
|
|
|
return &Cache{
|
|
|
|
Path: path,
|
|
|
|
}
|
|
|
|
}
|