xzmapitem

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2023 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any](value T, opts ...Option[T]) *item[T]

默认不删除缓存

Types

type Item

type Item[T any] interface {
	GetValue() T                             // 获取缓存值
	VerifyExpiration(unixNano int64) bool    // 判断是否过期
	VerifyTimeDuration(d time.Duration) bool // 判断是否超过时间
	DeleteHandler()                          // 删除执行函数
}

type Option

type Option[T any] func(item *item[T])

func WithDeleteHandler

func WithDeleteHandler[T any](fn func(v T)) Option[T]

设置删除函数

func WithDurationDays

func WithDurationDays[T any](days int) Option[T]

设置过期时间(天)

func WithDurationHours

func WithDurationHours[T any](hours int) Option[T]

设置过期时间(小时)

func WithDurationMinutes

func WithDurationMinutes[T any](minutes int) Option[T]

设置过期时间(分钟)

func WithDurationMonths

func WithDurationMonths[T any](months int) Option[T]

设置过期时间(月份)

func WithDurationSeconds

func WithDurationSeconds[T any](seconds int) Option[T]

设置过期时间(秒)

func WithExpiration

func WithExpiration[T any](expiration int64) Option[T]

设置过期时间

func WithNoExpiration

func WithNoExpiration[T any]() Option[T]

无过期时间

Jump to

Keyboard shortcuts

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