bzeasycache

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 2 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 New

func New[T any](opts ...Option[T]) *Cache[T]

func (*Cache[T]) ExistOrPut

func (c *Cache[T]) ExistOrPut(key string, val T, t ...time.Duration) bool

ExistOrPut 如果不存在则创建,存在则不创建,如redis setnx @return bool 是否存在

func (*Cache[T]) Get

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

Get 获取

func (*Cache[T]) GetOrPut

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

GetOrPut 存在则正常获取,不存在则创建默认值并返回

func (*Cache[T]) Put

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

Put 设置

func (*Cache[T]) PutLockFunc

func (c *Cache[T]) PutLockFunc(key string, f func() (T, time.Duration, error)) error

PutLockFunc 设置并支持幂等性方法

type CacheItem

type CacheItem[T any] struct {
	Data    T
	EndTime int64
}

type Option

type Option[T any] func(c *Cache[T])

func WithDefaultExpiresTime

func WithDefaultExpiresTime[T any](t time.Duration) Option[T]

func WithInitMapCap

func WithInitMapCap[T any](cap int) Option[T]

Jump to

Keyboard shortcuts

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