ttl

package module
v0.0.0-...-76cac20 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: GPL-3.0 Imports: 2 Imported by: 36 modules, 51 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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]) GetAndDelete

func (c *Cache[K, V]) GetAndDelete(key K) (v V, deleted bool)

Delete 获得值后删除指定key

func (*Cache[K, V]) GetOrSet

func (c *Cache[K, V]) GetOrSet(key K, val V) (v V, got bool)

GetOrSet 获取 key 的值或在为空时设置 key 的值并返回该值

func (*Cache[K, V]) Range

func (c *Cache[K, V]) Range(f func(K, V) error) error

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
⌂ 换网址