Documentation
¶
Overview ¶
Package cleancache provides a thread-safe weak pointer cache that automatically cleans up entries when the weakly referenced objects are garbage collected. It supports basic operations like Get, Set, and Del. It uses a shared map for concurrency that also shrinks with deleted keys. The sharded map is based on Tidwall's shardedmap implementation, but updated for generics and uses the maphash package. The cache has no size limit and relies on Go's runtime to manage memory once objects are no longer referenced. Unlike the base version at cleancache/cache.go, this version does not use a custom hashmap implementation, but instead uses a sharded map from the gostdlib library. These are virtually identical except the other optimizes a few calls at a lower level. This version is simpler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache is a weakPointer cache. It provides a cache of objects that have weak pointers to them. When the weak pointer's value becomes nil, we delete the key. This cache is thread-safe.
func (*Cache[K, V]) Del ¶
Del deletes a value for a key. Returns the deleted value, or false when no value was assigned.