knife

package
v1.1.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: Apache-2.0 Imports: 5 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.Set(ctx, "a", "b")
v, ok = knife.Get(ctx, "a")

var m map[string]string
ok, err := knife.Fetch(ctx, "a", &m)

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var ErrUninitialized = errors.New("knife uninitialized")

ErrUninitialized context.Context 对象未初始化。

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 Fetch

func Fetch(ctx context.Context, key string, out interface{}) (bool, error)

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

func Get

func Get(ctx context.Context, key string) (interface{}, bool)

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

func New

func New(ctx context.Context) (dst 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 Set

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

Set 将 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