cache

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: GPL-3.0 Imports: 7 Imported by: 1

Documentation

Overview

Package cache : 数据缓存模块,可定时清理过期数据

Usage

package main

import (
	"github.com/xyzj/gopsu/cache"
)

func main() {
	mycache:=cache.NewCache(1000) //  max 1000 data
	defer mycache.End() // clean up and stop zhe data expire check
	mycache.Set("123","abc")
	v,ok:=mycache.Get("123")
	if !ok{
		println("key not found")
		return
	}
	println(v)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type XCache

type XCache struct {
	// contains filtered or unexported fields
}

XCache 可设置超时的缓存字典

func NewCache

func NewCache(max int) *XCache

NewCache 创建新的缓存字典

max:字典大小,0-不限制(谨慎使用)

func NewCacheWithWriter added in v1.3.5

func NewCacheWithWriter(max int, logw io.Writer) *XCache

NewCacheWithWriter 创建新的缓存字典,并指定panic日志输出writer

max:字典大小,0-不限制(谨慎使用)

func (*XCache) Clean added in v1.3.5

func (xc *XCache) Clean()

Clean 清空缓存

func (*XCache) End added in v1.3.5

func (xc *XCache) End()

End 关掉这个cache

func (*XCache) Get

func (xc *XCache) Get(k string) (interface{}, bool)

Get 读取缓存数据

func (*XCache) GetAndExpire

func (xc *XCache) GetAndExpire(k string, expire time.Duration) (interface{}, bool)

GetAndExpire 读取缓存数据,并延长缓存时效

func (*XCache) GetAndRemove

func (xc *XCache) GetAndRemove(k string) (interface{}, bool)

GetAndRemove 读取缓存数据,并删除

func (*XCache) Len

func (xc *XCache) Len() int

Len 获取缓存数量

func (*XCache) Set

func (xc *XCache) Set(k string, v interface{}, expire time.Duration) bool

Set 设置缓存数据

k: key

v: value

expire: 超时时间,有效单位秒

func (*XCache) SetWithHold

func (xc *XCache) SetWithHold(k string, v interface{}, expire, timeout time.Duration) bool

SetWithHold 设置缓存数据

k: key

v: value

expire: 超时时间,有效单位秒

timeout: 写入超时,有效单位秒

Jump to

Keyboard shortcuts

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