bcache

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

bcache

byte cache

Install

go get github.com/aacfactory/bcache

Usage

cache := bcache.New()
setErr := cache.Set([]byte("key"), []byte("value"))
value, has := cache.Get([]byte("key"))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooBigKey  = fmt.Errorf("key was too big, must not be greater than 63k")
	ErrInvalidKey = fmt.Errorf("key is invalid")
)

Functions

This section is empty.

Types

type Cache

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

func New

func New(options ...Option) (cache *Cache)

func (*Cache) Contains

func (c *Cache) Contains(k []byte) bool

func (*Cache) Expire

func (c *Cache) Expire(k []byte, ttl time.Duration)

func (*Cache) Get

func (c *Cache) Get(k []byte) (p []byte, ok bool)

func (*Cache) Remove

func (c *Cache) Remove(k []byte)

func (*Cache) Set

func (c *Cache) Set(k []byte, v []byte) (err error)

func (*Cache) SetWithTTL

func (c *Cache) SetWithTTL(k []byte, v []byte, ttl time.Duration) (err error)

type Entries

type Entries []Entry

func MakeEntries

func MakeEntries(k []byte, p []byte, ttl time.Duration, hash Hash) (entries Entries)

func (Entries) Deadline

func (entries Entries) Deadline() time.Time

func (Entries) Value

func (entries Entries) Value() (p []byte)

type Entry

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

func (Entry) Hash

func (kv Entry) Hash() uint64

func (Entry) Key

func (kv Entry) Key() []byte

func (Entry) Value

func (kv Entry) Value() Value

type Hash

type Hash interface {
	Sum(p []byte) (h uint64)
}

type MemHash

type MemHash struct{}

func (MemHash) Sum

func (hash MemHash) Sum(p []byte) (h uint64)

type Option

type Option func(opt *Options)

func MaxBytes

func MaxBytes(n uint64) Option

func WithHash

func WithHash(h Hash) Option

type Options

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

type Value

type Value []byte

Value [1]pos [1]size, [8]deadline, [...]value

func (Value) BigKey

func (v Value) BigKey() bool

func (Value) Bytes

func (v Value) Bytes() (p []byte)

func (Value) Deadline

func (v Value) Deadline() time.Time

func (Value) Normal

func (v Value) Normal() bool

func (Value) Pos

func (v Value) Pos() int

func (Value) SetDeadline

func (v Value) SetDeadline(deadline time.Time)

func (Value) Size

func (v Value) Size() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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