From 994cae9179f7ec260abe6590feb6a5555eddbb2b Mon Sep 17 00:00:00 2001 From: Eric Buth Date: Tue, 30 Dec 2025 12:01:53 -0500 Subject: [PATCH 1/2] docs: add pkg.go.dev badge and type docs Add documentation for the `weakmap` package: * Add Go Reference badge to `README.md` linking to pkg.go.dev * Document `Map` type describing its purpose as a concurrent cache with weak pointers and automatic cleanup * Document `New` field explaining its role in value creation * Improve `Load` method documentation clarifying behavior when values are garbage collected or `New` is nil --- README.md | 2 ++ weakmap.go | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c0db0a2..d54e34b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # weakmap +[![Go Reference](https://pkg.go.dev/badge/github.com/acycl/weakmap.svg)](https://pkg.go.dev/github.com/acycl/weakmap) + A generic cache map implementation with [weak pointers](https://pkg.go.dev/weak#Pointer) as described [on the Go blog](https://go.dev/blog/cleanups-and-weak#weak-pointers). diff --git a/weakmap.go b/weakmap.go index dacd479..8d3c286 100644 --- a/weakmap.go +++ b/weakmap.go @@ -9,12 +9,22 @@ import ( "weak" ) +// Map is a concurrent cache that stores values as weak pointers. Values are +// created on demand via the New function and automatically removed from the +// cache when they are no longer referenced elsewhere and garbage collected. +// +// A Map must not be copied after first use. type Map[K comparable, V any] struct { + // New creates a value for the given key. It is called when Load is invoked + // for a key that is not in the cache or whose cached value has been + // collected. If New is nil, Load always returns nil. New func(K) *V cache sync.Map } -// Load retrieves a value from the cache. +// Load retrieves a value from the cache, creating it via New if necessary. +// If the cached value has been garbage collected, New is called again to +// create a fresh value. Returns nil if New is nil. func (m *Map[K, V]) Load(key K) *V { if m.New == nil { return nil From 9c14f8c7b93bae357f0842468fcbfa282ea01f04 Mon Sep 17 00:00:00 2001 From: Eric Buth Date: Sun, 15 Feb 2026 13:01:48 -0500 Subject: [PATCH 2/2] ci: update Go versions and workflow triggers Update CI configuration and minimum Go version. * Restrict push triggers to `main` and add `pull_request` trigger in `.github/workflows/go.yml` * Update Go version matrix from 1.24/1.25 to 1.25/1.26 * Bump minimum Go version to 1.25.0 in `go.mod` --- .github/workflows/go.yml | 7 +++++-- go.mod | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 28f94bd..0fbee46 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,12 +1,15 @@ name: Go -on: [push] +on: + push: + branches: [main] + pull_request: jobs: test: strategy: matrix: go-version: - - '1.24' - '1.25' + - '1.26' runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 diff --git a/go.mod b/go.mod index e0bc3fc..858062c 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/acycl/weakmap -go 1.24.0 +go 1.25.0 require golang.org/x/sync v0.19.0