cache

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyName = ""

Variables

This section is empty.

Functions

func NewLocation

func NewLocation(name string) *location

Types

type Cache

type Cache[T any] struct {
	ICache ICache
}

Cache 定义范型,T为保存的数据类型

func (*Cache[T]) Add

func (c *Cache[T]) Add(key string, val any, d time.Duration) bool

func (*Cache[T]) Forever

func (c *Cache[T]) Forever(key string, val T)

func (*Cache[T]) Get

func (c *Cache[T]) Get(key string, defaultValue T) T

func (*Cache[T]) Has

func (c *Cache[T]) Has(key string) bool

func (*Cache[T]) Put

func (c *Cache[T]) Put(key string, val T, d time.Duration)

type ICache

type ICache interface {
	// Add 写入不存在的项目
	Add(key string, val any, d time.Duration) bool
	// Put 存储到缓存中
	Put(key string, val any, d time.Duration)
	// Has 判断项目是否存在
	Has(key string) bool
	// Get 获取项目
	Get(key string, defaultValue any) any
	// Forever 永久写入项目
	Forever(key string, val any)
}

ICache 定义缓存接口

Jump to

Keyboard shortcuts

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