lrucache

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opt *Option) (fscache.Cache, error)

New 创建新的 lru 缓存实例

参数 opt:必填

Example
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/fsgo/fscache/lrucache"
)

func main() {
	cache, err := lrucache.New(&lrucache.Option{Capacity: 1000})
	fmt.Println("err_is_nil=", err == nil)

	ret := cache.Set(context.Background(), "k1", "v1", time.Second)
	fmt.Println("set_success=", ret.Err == nil)

}
Output:

err_is_nil= true
set_success= true

func NewSCache

func NewSCache(opt *Option) (fscache.SCache, error)

NewSCache 创建普通(非批量)

Types

type Option

type Option struct {
	// Capacity 缓存个数,必填,不得小于 1
	Capacity int
}

Option LRU缓存的配置

func (*Option) Check

func (o *Option) Check() error

Check 检查配置是否正常

func (*Option) GetCapacity

func (o *Option) GetCapacity() int

GetCapacity 获取容量

type SCache

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

SCache lru 普通缓存

func (*SCache) Delete

func (L *SCache) Delete(ctx context.Context, key any) fscache.DeleteResult

Delete 删除

func (*SCache) Get

func (L *SCache) Get(ctx context.Context, key any) fscache.GetResult

Get 读取

func (*SCache) Has

func (L *SCache) Has(ctx context.Context, key any) fscache.HasResult

Has 判断是否存在

func (*SCache) Reset

func (L *SCache) Reset(ctx context.Context) error

Reset 重置、清空所有缓存

func (*SCache) Set

func (L *SCache) Set(ctx context.Context, key any, val any, ttl time.Duration) fscache.SetResult

Set 设置

Jump to

Keyboard shortcuts

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