ttl

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

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

Go to latest
Published: Mar 7, 2023 License: GPL-3.0 Imports: 2 Imported by: 33

README

ttl

The independent repo of ZeroBot/extension/ttl

Documentation

Overview

Package ttl provides a synchronised map that auto-expire

This package is simply to provide a storage for session.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Cache is a synchronised map of items that auto-expire once stale

func NewCache

func NewCache[K comparable, V any](ttl time.Duration) *Cache[K, V]

NewCache 创建指定生命周期的 Cache

func NewCacheOn

func NewCacheOn[K comparable, V any](ttl time.Duration, on [4]func(K, V)) *Cache[K, V]

NewCacheOn 创建指定生命周期的 Cache

on: [onset, onget, ondel, ontouch]

func (*Cache[K, V]) Delete

func (c *Cache[K, V]) Delete(key K)

Delete 删除指定key

func (*Cache[K, V]) Destroy

func (c *Cache[K, V]) Destroy()

Destroy 销毁 chahe, 不可再使用, 否则 panic

func (*Cache[K, V]) Get

func (c *Cache[K, V]) Get(key K) (v V)

Get 通过 key 获取指定的元素

func (*Cache[K, V]) Set

func (c *Cache[K, V]) Set(key K, val V)

Set 设置指定 key 的值

func (*Cache[K, V]) Touch

func (c *Cache[K, V]) Touch(key K, ttl time.Duration)

Touch 为指定key添加一定生命周期

type Item

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

Item represents a record in the cache map

Jump to

Keyboard shortcuts

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