Skip to content

feat: Prefix keys with namespace (strategy name)#129

Merged
nssherpa merged 5 commits intomainfrom
nsherpa/s3-strategy-prefix
Feb 24, 2026
Merged

feat: Prefix keys with namespace (strategy name)#129
nssherpa merged 5 commits intomainfrom
nsherpa/s3-strategy-prefix

Conversation

@nssherpa
Copy link
Collaborator

@nssherpa nssherpa commented Feb 19, 2026

Testing

Steps

  1. Run cachew
just docker build && docker run --rm -it \   ✔  12:10:51 PM 
-p 8080:8080 \
-v ~/.scripts/github/blox-cache.2026-02-03.private-key.pem:/app/github-app-key.pem:ro \
-e CACHEW_GITHUB_APP_APP_ID="2666596" \
-e CACHEW_GITHUB_APP_PRIVATE_KEY_PATH="/app/github-app-key.pem" \
cachew:local
  1. Updated cachew. hcl file
git {
 #bundle-interval = "24h"
-  #snapshot-interval = "24h"
+  snapshot-interval = "2s"
}

host "https://w3.org" {}

github-releases {
 token = "${GITHUB_TOKEN}"
-  private-orgs = ["alecthomas"]
+  private-orgs = []
}

disk {
 root = "./state/cache"
-  limit-mb = 250000
-  max-ttl = "8h"
+  limit-mb = 5              # Lower limit to trigger eviction faster
+  max-ttl = "1h"              # Shorter TTL
+  evict-interval = "10s"      # Check for eviction more frequently (default: 1m)
}
  1. Commands run
time git clone --depth 1000 http://localhost:8080/git/github.com/squareup/blox.git /tmp/blox
time curl http://localhost:8080/hermit/github.com/alecthomas/mk/releases/download/v0.9.2/mk-x86_64-unknown-linux-gnu.bz2  -o /tmp/test-download-hermit-pkg
curl -O http://localhost:8080/gomod/github.com/alecthomas/kong/@v/v0.9.0.zip
  1. Check boltdb. Copy boltdb first
docker cp 971d3bb9f27d:/app/state/cache/metadata.db /tmp/metadata.db
Successfully copied 34.3kB to /tmp/metadata.db
❯ bbolt keys /tmp/metadata.db ttl
github-releases/1e62d156144a1e1643f1153fefae077177f2f36e8a3da9aab290632312b22e86
gomod/37f64a6175817977786b233eadfb01a8a17b3dc7cd89f32bd3e5052a9e8c835f
gomod/d81d8126b23c945f5f797268e297874f64c2b02b9d89954ee607e7b3a11dddcd
gomod/e9aac1903b81621a454a6cc20cdbeedee5744f6f467b2da1491a83ff5400b7ed
bbolt stats /tmp/metadata.db
Aggregate statistics for 2 buckets

Page count statistics
	Number of logical branch pages: 0
	Number of physical branch overflow pages: 0
	Number of logical leaf pages: 1
	Number of physical leaf overflow pages: 0
Tree statistics
	Number of keys/value pairs: 8
	Number of levels in B+tree: 1
Page size utilization
	Bytes allocated for physical branch pages: 0
	Bytes actually used for branch data: 0 (0%)
	Bytes allocated for physical leaf pages: 4096
	Bytes actually used for leaf data: 1419 (34%)
Bucket statistics
	Total number of buckets: 2
	Total number on inlined buckets: 1 (50%)
	Bytes used for inlined buckets: 430 (30%)

Results

Per strategy name directory in the cache folder

Screenshot 2026-02-19 at 8 25 43 PM Screenshot 2026-02-19 at 8 01 44 PM Screenshot 2026-02-19 at 8 28 04 PM
Every 1.0s: curl -s http://localhost:8080/api/v1/stats | jq                                                                                                             BLKL5XW75Q41X.local: Thu Feb 19 20:28:34 2026
                                                                                                                                                                                                        in 0.058s (0)
{
  "objects": 5,
  "size": 3055418,
  "capacity": 5242880
}

Testing cache eviction

Issued a series of hermit package download and go mod requests

Cachew removed the old entries after hitting the size limit, you can see the older go-mod entries being removed from boltdb but not from state/cache. But also that the cache is a global cache, and eviction works with the global namespace.

Screenshot 2026-02-23 at 12 22 38 PM Screenshot 2026-02-23 at 12 22 48 PM
  ❯ docker cp 971d3bb9f27d:/app/state/cache/metadata.db /tmp/metadata.db
  Successfully copied 67.1kB to /tmp/metadata.db
  ❯ bbolt keys /tmp/metadata.db ttl
  github-releases/6d55ea4b196913a593885e537356af12b24905ab3aceca9c148b6d2ebc09623d
  github-releases/bc73abb56921b57e7192549786a97e816e6905f76106f43f93c4f7397a70d0fd
  github-releases/d5556f8b7e2fd2454733d5770d72667ef10a4e17c4d451e4e8052fb891c9a3b9

Testing cachew cli

  1. List namespaces
❯ cachew namespaces
github-releases
gomod
  1. Put key with namespace
echo "hello world" | cachew put myns my-test-key
  1. Namespace created on disk and bbolt db
/app $ ls -la state/cache/
total 68
drwxr-xr-x    1 cachew   cachew        4096 Feb 23 20:30 .
drwxr-xr-x    1 cachew   cachew        4096 Feb 23 20:04 ..
drwxr-x---    3 cachew   cachew        4096 Feb 23 20:10 git
drwxr-x---    7 cachew   cachew        4096 Feb 23 20:22 github-releases
drwxr-x---    5 cachew   cachew        4096 Feb 23 20:13 gomod
-rw-------    1 cachew   cachew       65536 Feb 23 20:30 metadata.db
drwxr-x---    3 cachew   cachew        4096 Feb 23 20:30 myns
❯ bbolt keys /tmp/metadata.db ttl
github-releases/6d55ea4b196913a593885e537356af12b24905ab3aceca9c148b6d2ebc09623d
github-releases/bc73abb56921b57e7192549786a97e816e6905f76106f43f93c4f7397a70d0fd
github-releases/d5556f8b7e2fd2454733d5770d72667ef10a4e17c4d451e4e8052fb891c9a3b9
gomod/37f64a6175817977786b233eadfb01a8a17b3dc7cd89f32bd3e5052a9e8c835f
gomod/d81d8126b23c945f5f797268e297874f64c2b02b9d89954ee607e7b3a11dddcd
gomod/e9aac1903b81621a454a6cc20cdbeedee5744f6f467b2da1491a83ff5400b7ed
myns/20eb0536650933acad4ae017f3df774426ea2e4187d13728c99a6baf5e37b2b3
❯ cachew namespaces
github-releases
gomod
myns
❯ cachew stat myns my-test-key
Last-Modified: Mon, 23 Feb 2026 20:30:21 GMT
❯ cachew get myns my-test-key
Content-Type: text/plain; charset=utf-8
Last-Modified: Mon, 23 Feb 2026 20:30:21 GMT
hello world

  1. Delete the key
❯ cachew delete myns my-test-key
❯ cachew namespaces
github-releases
gomod
myns
  1. Namespace isolation test, using the same key in both namespaces
❯ KEY=$(echo -n "isolation-test" | sha256sum | awk '{print $1}')
❯ echo "namespace-A content" | ./cachew --url http://localhost:8080 put ns-alpha $KEY
cachew: error: unknown flag --url
❯ echo "namespace-A content" | cachew put ns-alpha $KEY
❯ echo "namespace-B content" | cachew put ns-beta $KEY
❯ cachew get ns-alpha $KEY
Last-Modified: Mon, 23 Feb 2026 20:35:27 GMT
Content-Type: text/plain; charset=utf-8
namespace-A content
❯ cachew get ns-beta $KEY
Last-Modified: Mon, 23 Feb 2026 20:35:41 GMT
Content-Type: text/plain; charset=utf-8
namespace-B content
❯ cachew get ns-gamma $KEY
cachew: error: failed to open object: file does not exist
❯ cachew namespaces
github-releases
gomod
myns
ns-alpha
ns-beta

Testing apiV1

Screenshot 2026-02-23 at 12 39 03 PM
❯ curl -s http://localhost:8080/api/v1/namespaces | jq
[
  "github-releases",
  "gomod",
  "myns",
  "ns-alpha",
  "ns-beta"
]
❯ cachew namespaces
github-releases
gomod
myns
ns-alpha
ns-beta
❯ bbolt keys /tmp/metadata.db ttl
❯ docker cp 971d3bb9f27d:/app/state/cache/metadata.db /tmp/metadata.db
Successfully copied 67.1kB to /tmp/metadata.db
❯ cachew namespaces
❯ bbolt keys /tmp/metadata.db ttl
github-releases/6d55ea4b196913a593885e537356af12b24905ab3aceca9c148b6d2ebc09623d
github-releases/bc73abb56921b57e7192549786a97e816e6905f76106f43f93c4f7397a70d0fd
github-releases/d5556f8b7e2fd2454733d5770d72667ef10a4e17c4d451e4e8052fb891c9a3b9
gomod/37f64a6175817977786b233eadfb01a8a17b3dc7cd89f32bd3e5052a9e8c835f
gomod/d81d8126b23c945f5f797268e297874f64c2b02b9d89954ee607e7b3a11dddcd
gomod/e9aac1903b81621a454a6cc20cdbeedee5744f6f467b2da1491a83ff5400b7ed
ns-alpha/a509236b69912cbd19fcadecd7e329aeec2de2c13cca3a1466dd7beda07de50a
ns-beta/a509236b69912cbd19fcadecd7e329aeec2de2c13cca3a1466dd7beda07de50a

@nssherpa nssherpa force-pushed the nsherpa/s3-strategy-prefix branch 9 times, most recently from c7ba70b to 9c72769 Compare February 20, 2026 04:23
@nssherpa nssherpa marked this pull request as ready for review February 20, 2026 04:28
@nssherpa nssherpa requested a review from a team as a code owner February 20, 2026 04:28
@nssherpa nssherpa requested review from alecthomas and removed request for a team February 20, 2026 04:28
@nssherpa nssherpa changed the title feat: Prefix keys with strategy name feat: Prefix keys with namespace (strategy name) Feb 20, 2026
@nssherpa nssherpa force-pushed the nsherpa/s3-strategy-prefix branch from 9b7b293 to 0f1fc8f Compare February 23, 2026 21:08
@nssherpa nssherpa merged commit 6731598 into main Feb 24, 2026
6 checks passed
@nssherpa nssherpa deleted the nsherpa/s3-strategy-prefix branch February 24, 2026 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants