diff options
author | Marc Pervaz Boocha <mboocha@sudomsg.com> | 2025-07-27 15:06:09 +0530 |
---|---|---|
committer | Marc Pervaz Boocha <mboocha@sudomsg.com> | 2025-07-27 16:36:28 +0530 |
commit | 0e46b370f0378f17f24481eb5d9526b690ecadb9 (patch) | |
tree | cc751fd4f9a5b12b74446b1dcb81aff6ce5fdd34 /conn.go | |
parent | Add raw API (diff) | |
download | cache-0.1.1.tar cache-0.1.1.tar.gz cache-0.1.1.tar.bz2 cache-0.1.1.tar.lz cache-0.1.1.tar.xz cache-0.1.1.tar.zst cache-0.1.1.zip |
Diffstat (limited to 'conn.go')
-rw-r--r-- | conn.go | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -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 -} |