weakmap

package module
v0.0.0-...-82c1181 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 3 Imported by: 1

README

weakmap

A generic cache map implementation with weak pointers as described on the Go blog.

Usage

To initialize a Map instance, provide a method for instantiating new values given a key.

m := Map[int, string]{
    New: func(key int) *string {
        value := strconv.Itoa(key)
        return &value
    },
}

k := 1
v := m.Load(k) // *v == "1"

Instances are safe for concurrent use but should not be copied.

Documentation

Overview

Package weakmap provides 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).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

type Map[K comparable, V any] struct {
	New func(K) *V
	// contains filtered or unexported fields
}

func (*Map[K, V]) Load

func (m *Map[K, V]) Load(key K) *V

Load retrieves a value from the cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL