knife

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

knife

提供了 context.Context 上的缓存。

Install

go get github.com/go-spring/spring-base@v1.1.0-rc2 

Import

import "github.com/go-spring/spring-base/knife"

Example

ctx = knife.New(context.Background())
err = knife.Store(ctx, "a", "b")
v, err := knife.Load(ctx, "a")

Documentation

Overview

Package knife 提供了 context.Context 上的缓存。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(src context.Context, keys ...string) (context.Context, error)

Copy 拷贝 context.Context 对象中的内容到另一个 context.Context 对象。

func Delete

func Delete(ctx context.Context, key string)

Delete 从 context.Context 对象中删除 key 及其对应的 val 。

func Load

func Load(ctx context.Context, key string) (interface{}, error)

Load 从 context.Context 对象中获取 key 对应的 val。

func LoadOrStore

func LoadOrStore(ctx context.Context, key string, val interface{}) (actual interface{}, loaded bool, err error)

LoadOrStore 将 key 及其 val 保存到 context.Context 对象。

func New

func New(ctx context.Context) (_ context.Context, cached bool)

New 返回带有缓存空间的 context.Context 对象,已绑定缓存空间时 cached 返回 true 。

func Range

func Range(ctx context.Context, f func(key, value interface{}) bool)

Range 遍历 context.Context 对象中所有的 key 和 val 。

func Store

func Store(ctx context.Context, key string, val interface{}) error

Store 将 key 及其 val 保存到 context.Context 对象。

Types

This section is empty.

Jump to

Keyboard shortcuts

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