cache

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

A Cache object is a in-memory cache.

func NewCache

func NewCache(expire time.Duration, opts ...CacheOption) (*Cache, error)

NewCache returns a Cache with given expire.

func (*Cache) Del

func (c *Cache) Del(key string)

Del deletes the item with the given key from c.

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get returns the item with the given key from c.

func (*Cache) Set

func (c *Cache) Set(key string, value interface{})

Set sets value into c with key.

func (*Cache) Take

func (c *Cache) Take(key string, fetch func() (interface{}, error)) (interface{}, error)

Take returns the item with the given key. If the item is in c, return it directly. If not, use fetch method to get the item, set into c and return it.

type CacheOption

type CacheOption func(cache *Cache)

CacheOption defines the method to customize a Cache.

func WithLimit

func WithLimit(limit int) CacheOption

WithLimit customizes a Cache with items up to limit.

func WithName

func WithName(name string) CacheOption

WithName customizes a Cache with the given name.

Jump to

Keyboard shortcuts

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