cache

package
v0.1.83 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[Key any, Value any] struct {
	// contains filtered or unexported fields
}

Cache is cache struct.

func New

func New[Key any, Value any]() *Cache[Key, Value]

New creates a new cache with auto clean or not.

func (*Cache[Key, Value]) Clear

func (c *Cache[Key, Value]) Clear()

Clear deletes all values in cache.

func (*Cache[Key, Value]) Delete

func (c *Cache[Key, Value]) Delete(key *Key)

Delete deletes the value for a key.

func (*Cache[Key, Value]) Get

func (c *Cache[Key, Value]) Get(key *Key) (value Value, ok bool)

Get gets cache value by key and whether value was found.

func (*Cache[Key, Value]) Set

func (c *Cache[Key, Value]) Set(key *Key, value Value)

Set sets cache value for a key.

func (*Cache[Key, Value]) Swap

func (c *Cache[Key, Value]) Swap(key *Key, value Value) (previous Value, loaded bool)

Swap swaps the value for a key and returns the previous value if any. The loaded result reports whether the key was present.

type CacheWithRenew added in v0.1.75

type CacheWithRenew[Key comparable, Value any] struct {
	// contains filtered or unexported fields
}

CacheWithRenew is cache struct.

func NewWithRenew added in v0.1.75

func NewWithRenew[Key comparable, Value any](autoRenew bool) *CacheWithRenew[Key, Value]

NewWithRenew creates a new cache with auto clean or not.

func (*CacheWithRenew[Key, Value]) Clear added in v0.1.75

func (c *CacheWithRenew[Key, Value]) Clear()

Clear deletes all values in cache.

func (*CacheWithRenew[Key, Value]) Delete added in v0.1.75

func (c *CacheWithRenew[Key, Value]) Delete(key Key)

Delete deletes the value for a key.

func (*CacheWithRenew[Key, Value]) Get added in v0.1.75

func (c *CacheWithRenew[Key, Value]) Get(key Key) (value Value, ok bool)

Get gets cache value by key and whether value was found.

func (*CacheWithRenew[Key, Value]) Set added in v0.1.75

func (c *CacheWithRenew[Key, Value]) Set(key Key, value Value, lifecycle time.Duration, fn func() (Value, error))

Set sets cache value for a key, if fn is presented, this value will regenerate when expired.

func (*CacheWithRenew[Key, Value]) Swap added in v0.1.75

func (c *CacheWithRenew[Key, Value]) Swap(key Key, value Value) (previous Value, loaded bool)

Swap swaps the value for a key and returns the previous value if any. The loaded result reports whether the key was present.

Jump to

Keyboard shortcuts

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