aboutsummaryrefslogtreecommitdiffstats
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
parentAdd raw API (diff)
downloadcache-main.tar
cache-main.tar.gz
cache-main.tar.bz2
cache-main.tar.lz
cache-main.tar.xz
cache-main.tar.zst
cache-main.zip
Added Vanity Module Link.HEADv0.1.1main
-rw-r--r--LICENSE23
-rw-r--r--README.md18
-rw-r--r--conn.go35
-rw-r--r--examples/basic_usage/main.go2
-rw-r--r--examples/eviction_policy/main.go2
-rw-r--r--examples/eviction_policy_persistant/main.go2
-rw-r--r--go.mod2
-rw-r--r--store.go2
8 files changed, 55 insertions, 31 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..30d3c78
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,23 @@
+MIT License
+
+Copyright (c) 2025 Marc Pervaz Boocha
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+
diff --git a/README.md b/README.md
index 6d0054c..5026e2c 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,10 @@
An deamonless in-memory caching library with persistant snapshots.
+[Documentation](https://pkg.go.dev/go.sudomsg.com/cache)
+
+[Bug Tracker](https://github.com/marcthe12/cache)
+
## Features
- **In-Memory Cache**: Fast access to cached data.
@@ -21,7 +25,7 @@ An deamonless in-memory caching library with persistant snapshots.
To use the Cache Library in your Go project, you can install it using `go get`:
```sh
-go get github.com/marcthe12/cache
+go get go.sudomsg.com/cache
```
## Usage
@@ -34,7 +38,7 @@ go get github.com/marcthe12/cache
package main
import (
- "github.com/marcthe12/cache"
+ "go.sudomsg.com/cache"
"time"
"log"
)
@@ -68,7 +72,7 @@ To open an in-memory cache, use the `OpenMem` function:
package main
import (
- "github.com/marcthe12/cache"
+ "go.sudomsg.com/cache"
"time"
"log"
)
@@ -150,12 +154,4 @@ The Cache Library supports the following configuration options:
- `Memorize`: Attempts to retrieve a value from the cache. If the retrieval fails, it sets the result of the factory function into the cache and returns that result. Note this locks the db duing the factory function which prevent concurent acces to the db during the operation.
-## Documentation
-
- For detailed documentation on the public API, you can use `godoc`:
-
-```sh
-godoc -http=:6060
-```
-Then open your browser and navigate to `http://localhost:6060/pkg/github.com/marcthe12/cache`.
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
-}
diff --git a/examples/basic_usage/main.go b/examples/basic_usage/main.go
index 5b44cd9..cfbbaa3 100644
--- a/examples/basic_usage/main.go
+++ b/examples/basic_usage/main.go
@@ -4,7 +4,7 @@ import (
"fmt"
"time"
- "github.com/marcthe12/cache"
+ "go.sudomsg.com/cache"
)
func main() {
diff --git a/examples/eviction_policy/main.go b/examples/eviction_policy/main.go
index fa56b8f..3f040b5 100644
--- a/examples/eviction_policy/main.go
+++ b/examples/eviction_policy/main.go
@@ -5,7 +5,7 @@ import (
"os"
"time"
- "github.com/marcthe12/cache"
+ "go.sudomsg.com/cache"
)
func main() {
diff --git a/examples/eviction_policy_persistant/main.go b/examples/eviction_policy_persistant/main.go
index fc7cc32..8a79efa 100644
--- a/examples/eviction_policy_persistant/main.go
+++ b/examples/eviction_policy_persistant/main.go
@@ -5,7 +5,7 @@ import (
"os"
"time"
- "github.com/marcthe12/cache"
+ "go.sudomsg.com/cache"
)
func main() {
diff --git a/go.mod b/go.mod
index 58abdf7..22f2c8a 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module github.com/marcthe12/cache
+module go.sudomsg.com/cache
go 1.24.0
diff --git a/store.go b/store.go
index ccda46d..373247b 100644
--- a/store.go
+++ b/store.go
@@ -5,7 +5,7 @@ import (
"sync"
"time"
- "github.com/marcthe12/cache/internal/pausedtimer"
+ "go.sudomsg.com/cache/internal/pausedtimer"
)
const (