caches

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GCInterval        = 60 * time.Minute
	CacheGcMaxRemoved = 30
)

Variables

View Source
var (
	ErrNotFound         = errors.New("bkit/caches: not found")
	ErrSizeOverCapacity = errors.New("bkit/caches: memory size over set the capacity")
)

Functions

func FilenameExists

func FilenameExists(filename string) bool

func GetCurrentDir

func GetCurrentDir() (string, error)

GetCurrentDir -

func IsNotFoundErr

func IsNotFoundErr(err error) bool

Types

type CacheStore

type CacheStore interface {
	Get(key string) (interface{}, error)
	Set(key string, value interface{}) error
	Del(key string) error
	Range(f func(key, value interface{}) bool)
}

type Cacher

type Cacher interface {
	Get(key string) (interface{}, error)
	Range(f func(key string, value interface{}) bool) // Range Locks will be added. Watch for deadlocks

	Set(key string, value interface{}) error
	SetWithTTL(key string, value interface{}, ttl time.Duration) error

	Del(key string) error

	Close() error
}

type Disk

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

func NewDisk

func NewDisk(filename string) (*Disk, error)

NewDisk filename

func (*Disk) ReadFromFile

func (d *Disk) ReadFromFile() ([]byte, error)

ReadFromFile

func (*Disk) WriteToFile

func (d *Disk) WriteToFile(data []byte) error

WriteToFile if file exists, just del

type IValue

type IValue struct {
	Value       interface{} `json:"v"`
	ExpiredTime time.Time   `json:"e"`
	Size        int32       `json:"s"`
}

func (*IValue) Expired

func (val *IValue) Expired(now int64) bool

func (*IValue) SetExpiredTime

func (val *IValue) SetExpiredTime(t time.Duration)

func (*IValue) TTL

func (val *IValue) TTL() time.Duration

type LRUCache

type LRUCache struct {
	MaxElement int
	// contains filtered or unexported fields
}

func NewLRUCache

func NewLRUCache(store CacheStore, maxElement int) *LRUCache

NewLRUCache lru cache maxElement min set 100

func NewLRUMemory

func NewLRUMemory(maxElement int) *LRUCache

NewLRUMemory memory store

func (*LRUCache) Close

func (m *LRUCache) Close() error

func (*LRUCache) Del

func (m *LRUCache) Del(key string) error

func (*LRUCache) GC

func (m *LRUCache) GC()

GC if storage not enough, del little visit

func (*LRUCache) Get

func (m *LRUCache) Get(key string) (interface{}, error)

func (*LRUCache) Range added in v0.3.9

func (m *LRUCache) Range(f func(key string, value interface{}) bool)

func (*LRUCache) Set

func (m *LRUCache) Set(key string, val interface{}) error

func (*LRUCache) SetWithTTL

func (m *LRUCache) SetWithTTL(key string, val interface{}, ttl time.Duration) error

type LimitMemoryCache

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

LimitMemoryCache limit Memory use, implement cacher, suitable high performance, storage small.

func NewLimitMemoryCache

func NewLimitMemoryCache(size int32, filename ...string) *LimitMemoryCache

NewMemCache size=-1 not limit, 1<<20(1MB) filename if pass in, Close will save to file

func (*LimitMemoryCache) Close

func (m *LimitMemoryCache) Close() error

Close if enable save to file, save()

func (*LimitMemoryCache) Del

func (m *LimitMemoryCache) Del(key string) error

func (*LimitMemoryCache) Get

func (m *LimitMemoryCache) Get(key string) (interface{}, error)

func (*LimitMemoryCache) Range added in v0.3.9

func (m *LimitMemoryCache) Range(f func(key string, value interface{}) bool)

func (*LimitMemoryCache) Set

func (m *LimitMemoryCache) Set(key string, value interface{}) error

func (*LimitMemoryCache) SetWithTTL

func (m *LimitMemoryCache) SetWithTTL(key string, value interface{}, ttl time.Duration) error

type MemoryStore

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

MemoryStore represents in-memory store

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates a new store in memory

func (*MemoryStore) Del

func (s *MemoryStore) Del(key string) error

Del deletes object

func (*MemoryStore) Get

func (s *MemoryStore) Get(key string) (interface{}, error)

Get gets object from store

func (*MemoryStore) Range

func (s *MemoryStore) Range(f func(key, value interface{}) bool)

func (*MemoryStore) Set

func (s *MemoryStore) Set(key string, value interface{}) error

Set sets object into store

Jump to

Keyboard shortcuts

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