summaryrefslogtreecommitdiffstats
path: root/conn.go
diff options
context:
space:
mode:
authorMarc Pervaz Boocha <mboocha@sudomsg.com>2025-07-27 15:06:09 +0530
committerMarc Pervaz Boocha <mboocha@sudomsg.com>2025-07-27 16:36:28 +0530
commit0e46b370f0378f17f24481eb5d9526b690ecadb9 (patch)
treecc751fd4f9a5b12b74446b1dcb81aff6ce5fdd34 /conn.go
parentAdd raw API (diff)
downloadcache-0e46b370f0378f17f24481eb5d9526b690ecadb9.tar
cache-0e46b370f0378f17f24481eb5d9526b690ecadb9.tar.gz
cache-0e46b370f0378f17f24481eb5d9526b690ecadb9.tar.bz2
cache-0e46b370f0378f17f24481eb5d9526b690ecadb9.tar.lz
cache-0e46b370f0378f17f24481eb5d9526b690ecadb9.tar.xz
cache-0e46b370f0378f17f24481eb5d9526b690ecadb9.tar.zst
cache-0e46b370f0378f17f24481eb5d9526b690ecadb9.zip
Added Vanity Module Link.HEADv0.1.1main
Diffstat (limited to 'conn.go')
-rw-r--r--conn.go35
1 files changed, 20 insertions, 15 deletions
diff --git a/conn.go b/conn.go
index 0800ac9..812ef1b 100644
--- a/conn.go
+++ b/conn.go
@@ -12,6 +12,22 @@ import (
"github.com/vmihailenco/msgpack/v5"
)
+// The Core interface for cache
+type Cacher[K any, V any] interface {
+ Clear()
+ Close() error
+ Cost() uint64
+ Delete(key K) error
+ Error() error
+ Flush() error
+ Get(key K, value *V) (time.Duration, error)
+ GetValue(key K) (V, time.Duration, error)
+ Set(key K, value V, ttl time.Duration) error
+ SetConfig(options ...Option) error
+ Memorize(key K, factoryFunc func() (V, error), ttl time.Duration) (V, error)
+ UpdateInPlace(key K, processFunc func(V) (V, error), ttl time.Duration) error
+}
+
// cache represents a cache database with file-backed storage and in-memory operation.
type cache struct {
File io.WriteSeeker
@@ -272,12 +288,16 @@ type Cache[K any, V any] struct {
*cache
}
+var _ Cacher[any, any] = Cache[any, any]{}
+
// The CacheRaw database. Can be initialized by either OpenRaw or OpenRawFile or OpenRawMem. Uses per Cache Locks.
// CacheRaw represents a binary cache database with key-value pairs.
type CacheRaw struct {
*cache
}
+var _ Cacher[[]byte, []byte] = CacheRaw{}
+
// OpenRaw opens a binary cache database with the specified options. If filename is empty then in-memory otherwise file backed.
func OpenRaw(filename string, options ...Option) (CacheRaw, error) {
ret, err := open(filename, options...)
@@ -444,18 +464,3 @@ func (c Cache[K, V]) Memorize(key K, factoryFunc func() (V, error), ttl time.Dur
return value, nil
}
-
-type Cacher[K any, V any] interface {
- Clear()
- Close() error
- Cost() uint64
- Delete(key K) error
- Error() error
- Flush() error
- Get(key K, value *V) (time.Duration, error)
- GetValue(key K) (V, time.Duration, error)
- Memorize(key K, factoryFunc func() (V, error), ttl time.Duration) (V, error)
- Set(key K, value V, ttl time.Duration) error
- SetConfig(options ...Option) error
- UpdateInPlace(key K, processFunc func(V) (V, error), ttl time.Duration) error
-}