Cache.New
Overview
New creates a cache that evicts least-recently-used entries when size exceeds maxSize. Node: new LRUCache({ max: maxSize })
If you are coming from Node.js, the closest pattern is new LRUCache({ max }).
Method on Cache — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func New(maxSize int) *CacheCompare: Node.js · Standard Go · gox
js
const cache = new LRUCache({ max: 100 });go
// sync.Map or lru cache librarygo
import "github.com/sahilkhaire/gox/cache"
c := cache.New(100)Example
go
import "github.com/sahilkhaire/gox/cache"
c := cache.New(100)Tips
Obtain a Cache value first (see constructors on the package overview), then call New.
Standard library alternative
gox wraps the Go standard library or a trusted dependency with Node-familiar naming. You can use the underlying library directly — see the package overview for escape hatches.