cache

package
v10.0.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytes

type Bytes []byte

Bytes represents a cacheable byte slice.

func (Bytes) Size

func (b Bytes) Size() int

type Cache

type Cache interface {
	// Get returns the item with the given key, otherwise returns false.
	Get(ctx context.Context, key string) (Item, bool)

	// Set sets the item at the given key.
	Set(ctx context.Context, key string, i Item)

	// Deletes the item at the given key.
	Del(ctx context.Context, key string)

	// The number of items in the cache.
	Len() int

	// The size in bytes.
	Size() int
}

Cache is the interface that describes a cache.

type Expire

type Expire struct {
	// The duration while an item is cached.
	ItemTTL time.Duration
	// contains filtered or unexported fields
}

func (*Expire) Del

func (c *Expire) Del(ctx context.Context, key string)

func (*Expire) Get

func (c *Expire) Get(ctx context.Context, key string) (Item, bool)

func (*Expire) Len

func (c *Expire) Len() int

func (*Expire) Set

func (c *Expire) Set(ctx context.Context, key string, i Item)

func (*Expire) Size

func (c *Expire) Size() int

type Float

type Float float64

func (Float) Size

func (f Float) Size() int

type Int

type Int int

func (Int) Size

func (i Int) Size() int

type Item

type Item interface {
	// The size that the item occupies in a cache.
	Size() int
}

Item is the interface that describes a cacheable item.

type LRU

type LRU struct {
	// The maximum cache size in bytes. Default is 16MB.
	MaxSize int

	// The duration while an item is cached.
	ItemTTL time.Duration

	// The function called when an item is evicted.
	OnEvict func(key string, i Item)
	// contains filtered or unexported fields
}

LRU represents an LRU (Least Recently Used) cache implementation.

func (*LRU) Del

func (c *LRU) Del(ctx context.Context, key string)

func (*LRU) Get

func (c *LRU) Get(ctx context.Context, key string) (Item, bool)

func (*LRU) Len

func (c *LRU) Len() int

func (*LRU) Set

func (c *LRU) Set(ctx context.Context, key string, i Item)

func (*LRU) Size

func (c *LRU) Size() int

type String

type String string

func (String) Size

func (s String) Size() int

Jump to

Keyboard shortcuts

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