cache

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 2 Imported by: 3

Documentation

Overview

Package cache implements simple caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Manager represents a cache manager.

func New

func New[K comparable, V any](cap int, ttl time.Duration) *Manager[K, V]

New creates a new cache manager.

func (*Manager[K, V]) Cap added in v0.0.3

func (a *Manager[K, V]) Cap() int

Cap returns the cache manager capacity.

func (*Manager[K, V]) Delete

func (a *Manager[K, V]) Delete(key K)

Delete deletes the value for a key.

func (*Manager[K, V]) Len

func (a *Manager[K, V]) Len() int

Len returns the cache manager length.

func (*Manager[K, V]) Load

func (a *Manager[K, V]) Load(key K) (value V, ttl int64)

Load returns the value stored in the cache for a key, or zero value if no value is present.

func (*Manager[K, V]) LoadAndDelete

func (a *Manager[K, V]) LoadAndDelete(key K) (value V, ttl int64)

LoadAndDelete deletes the value for a key, returning the previous value if any.

func (*Manager[K, V]) LoadOrStore

func (a *Manager[K, V]) LoadOrStore(key K, value V) (actual V, ttl int64)

LoadOrStore returns the value by key, if not exist, puts value in the key, and returns it.

func (*Manager[K, V]) Store

func (a *Manager[K, V]) Store(key K, value V)

Store sets the value for a key.

func (*Manager[K, V]) TTL added in v0.0.3

func (a *Manager[K, V]) TTL() int64

TTL returns the cache manager time To live.

Jump to

Keyboard shortcuts

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