cache

package module
v0.0.0-...-f4ef023 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

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
}

并发安全内存库

func NewCache

func NewCache[T any](clearInterval time.Duration) *Cache[T]

func (*Cache[T]) Delete

func (c *Cache[T]) Delete(k string)

func (*Cache[T]) Get

func (c *Cache[T]) Get(k string) (v T, ok bool)

func (*Cache[T]) Story

func (c *Cache[T]) Story(k string, v T, d time.Duration)

存储,如果存在旧值则会覆盖过期时间

func (*Cache[T]) SwapValue

func (c *Cache[T]) SwapValue(k string, v T) bool

替换新值不覆盖过期时间

type Item

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

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRUCache is an LRU cache. It is safe for concurrent access.

func NewLRUCache

func NewLRUCache(maxItemSize int) *LRUCache

NewLRUCache If maxItemSize is zero, the cache has no limit. if maxItemSize is not zero, when cache's size beyond maxItemSize,start to swap

func (*LRUCache) Del

func (c *LRUCache) Del(key string)

Delete delete the key

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (interface{}, bool)

Get value with key

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value interface{})

Set a value with key

Jump to

Keyboard shortcuts

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