Skip to content

Commit 9bbc6d9

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
Rename pkg/persist to pkg/store, add null store
1 parent 3f0debd commit 9bbc6d9

File tree

25 files changed

+101
-34
lines changed

25 files changed

+101
-34
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ Designed for persistently caching API requests in an unreliable environment, thi
1616

1717
- **Faster than a bat out of hell** - Best-in-class latency and throughput
1818
- **S3-FIFO eviction** - Better hit-rates than LRU ([learn more](https://s3fifo.com/))
19-
- **L2 Persistence (optional)** - Bring your own database or use built-in backends:
20-
- [`pkg/persist/localfs`](pkg/persist/localfs) - Local files (gob encoding, zero dependencies)
21-
- [`pkg/persist/datastore`](pkg/persist/datastore) - Google Cloud Datastore
22-
- [`pkg/persist/valkey`](pkg/persist/valkey) - Valkey/Redis
23-
- [`pkg/persist/cloudrun`](pkg/persist/cloudrun) - Auto-detect Cloud Run
19+
- **Multi-tier persistent cache (optional)** - Bring your own database or use built-in backends:
20+
- [`pkg/store/cloudrun`](pkg/store/cloudrun) - Automatically select Google Cloud Datastore in Cloud Run, localfs elsewhere
21+
- [`pkg/store/datastore`](pkg/store/datastore) - Google Cloud Datastore
22+
- [`pkg/store/localfs`](pkg/store/localfs) - Local files (gob encoding, zero dependencies)
23+
- [`pkg/store/null`](pkg/store/null) - No-op (for testing or TieredCache API compatibility)
24+
- [`pkg/store/valkey`](pkg/store/valkey) - Valkey/Redis
2425
- **Per-item TTL** - Optional expiration
2526
- **Thundering herd prevention** - `GetSet` deduplicates concurrent loads for the same key
2627
- **Graceful degradation** - Cache works even if persistence fails
2728
- **Zero allocation updates** - minimal GC thrashing
28-
-
29+
2930
## Usage
3031

3132
As a stupid-fast in-memory cache:
@@ -44,7 +45,7 @@ Or as a multi-tier cache with local persistence to survive restarts:
4445
```go
4546
import (
4647
"github.com/codeGROOVE-dev/sfcache"
47-
"github.com/codeGROOVE-dev/sfcache/pkg/persist/localfs"
48+
"github.com/codeGROOVE-dev/sfcache/pkg/store/localfs"
4849
)
4950

5051
p, _ := localfs.New[string, User]("myapp", "")
@@ -57,7 +58,7 @@ cache.Store.Len(ctx) // Access persistence layer directly
5758
How about a persistent cache suitable for Cloud Run or local development? This uses Cloud DataStore if available, local files if not:
5859

5960
```go
60-
import "github.com/codeGROOVE-dev/sfcache/pkg/persist/cloudrun"
61+
import "github.com/codeGROOVE-dev/sfcache/pkg/store/cloudrun"
6162

6263
p, _ := cloudrun.New[string, User](ctx, "myapp")
6364
cache, _ := sfcache.NewTiered(p)
@@ -163,7 +164,7 @@ Want even more comprehensive benchmarks? See https://github.com/tstromberg/gocac
163164

164165
sfcache implements the core S3-FIFO algorithm (Small/Main/Ghost queues with frequency-based promotion) with these optimizations:
165166

166-
1. **Dynamic Sharding** - 1-256 independent S3-FIFO shards (vs single-threaded) for concurrent workloads
167+
1. **Dynamic Sharding** - 1-2048 independent S3-FIFO shards (vs single-threaded) for concurrent workloads
167168
2. **Bloom Filter Ghosts** - Two rotating Bloom filters track evicted keys (vs storing actual keys), reducing memory 10-100x
168169
3. **Lazy Ghost Checks** - Only check ghosts when evicting, saving 5-9% latency when cache isn't full
169170
4. **Intrusive Lists** - Embed pointers in entries (vs separate nodes) for zero-allocation queue ops

pkg/persist/cloudrun/go.mod

Lines changed: 0 additions & 14 deletions
This file was deleted.

pkg/persist/datastore/go.mod

Lines changed: 0 additions & 5 deletions
This file was deleted.

pkg/persist/localfs/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"os"
99
"time"
1010

11-
"github.com/codeGROOVE-dev/sfcache/pkg/persist/datastore"
12-
"github.com/codeGROOVE-dev/sfcache/pkg/persist/localfs"
11+
"github.com/codeGROOVE-dev/sfcache/pkg/store/datastore"
12+
"github.com/codeGROOVE-dev/sfcache/pkg/store/localfs"
1313
)
1414

1515
// Store is the persistence interface returned by New.

pkg/store/cloudrun/go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module github.com/codeGROOVE-dev/sfcache/pkg/store/cloudrun
2+
3+
go 1.25.4
4+
5+
require (
6+
github.com/codeGROOVE-dev/sfcache/pkg/store/datastore v1.3.0
7+
github.com/codeGROOVE-dev/sfcache/pkg/store/localfs v1.3.0
8+
)
9+
10+
require github.com/codeGROOVE-dev/ds9 v0.8.0 // indirect
11+
12+
replace github.com/codeGROOVE-dev/sfcache/pkg/store/datastore => ../datastore
13+
14+
replace github.com/codeGROOVE-dev/sfcache/pkg/store/localfs => ../localfs
File renamed without changes.

0 commit comments

Comments
 (0)