cache

package
v0.0.0-...-5fb8a3f Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package cache implements a cache. The cache hold 256 shards, each shard holds a cache: a map with a mutex. There is no fancy expunge algorithm, it just randomly evicts elements when it gets full.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is cache.

func New

func New[T any](size int) *Cache[T]

New returns a new cache.

func (*Cache[T]) Get

func (c *Cache[T]) Get(key uint64) (el T, exists bool)

Get returns the element under key, and whether the element exists.

func (*Cache[T]) GetOrPut

func (c *Cache[T]) GetOrPut(key uint64, newEl T) (el T, exists bool)

GetOrPut returns the element under key if it exists, or else stores newEl there. This operation is atomic.

func (*Cache[T]) Put

func (c *Cache[T]) Put(key uint64, el T)

Put adds a new element to the cache. If the element already exists, it is overwritten.

func (*Cache[T]) Remove

func (c *Cache[T]) Remove(key uint64)

Remove removes the element indexed with key.

Jump to

Keyboard shortcuts

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