ttl

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: GPL-3.0 Imports: 2 Imported by: 0

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 {
	sync.RWMutex
	// 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 (*Cache[K, V]) Delete

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

Delete 删除指定key

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