cache

package
v0.0.0-...-e044eaa Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache provides cache strategy support of the kv system, currently we have fifo, lru (default), lfu ...

Index

Constants

View Source
const (
	CACHE_STRATEGY_FIFO = "fifo"
	CACHE_STRATEGY_LRU  = "lru"
	CACHE_STRATEGY_LFU  = "lfu"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(key string) (Value, bool)
	Set(key string, value Value, ttl time.Duration)
	Remove(key string)
	Keys() []string
	Len() int
	Has(key string) bool
	Bytes() int64
	Shrink()
}

func NewDefaultCache

func NewDefaultCache(isHotCache bool) Cache

type FIFOCache

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

func (*FIFOCache) Bytes

func (c *FIFOCache) Bytes() int64

func (*FIFOCache) Get

func (c *FIFOCache) Get(key string) (value Value, ok bool)

func (*FIFOCache) Has

func (c *FIFOCache) Has(key string) bool

func (*FIFOCache) Keys

func (c *FIFOCache) Keys() []string

func (*FIFOCache) Len

func (c *FIFOCache) Len() int

func (*FIFOCache) Remove

func (c *FIFOCache) Remove(key string)

func (*FIFOCache) Set

func (c *FIFOCache) Set(key string, value Value, ttl time.Duration)

func (*FIFOCache) Shrink

func (c *FIFOCache) Shrink()

type LFUCache

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

func (*LFUCache) Bytes

func (c *LFUCache) Bytes() int64

func (*LFUCache) Get

func (c *LFUCache) Get(key string) (v Value, ok bool)

func (*LFUCache) Has

func (c *LFUCache) Has(key string) bool

func (*LFUCache) Keys

func (c *LFUCache) Keys() []string

func (*LFUCache) Len

func (c *LFUCache) Len() int

func (*LFUCache) Remove

func (c *LFUCache) Remove(key string)

func (*LFUCache) Set

func (c *LFUCache) Set(key string, value Value, ttl time.Duration)

func (*LFUCache) Shrink

func (c *LFUCache) Shrink()

type LRUCache

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

func (*LRUCache) Bytes

func (c *LRUCache) Bytes() int64

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (value Value, ok bool)

func (*LRUCache) Has

func (c *LRUCache) Has(key string) bool

func (*LRUCache) Keys

func (c *LRUCache) Keys() []string

func (*LRUCache) Len

func (c *LRUCache) Len() int

func (*LRUCache) Remove

func (c *LRUCache) Remove(key string)

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value Value, ttl time.Duration)

func (*LRUCache) Shrink

func (c *LRUCache) Shrink()

type Value

type Value interface {
	Len() int
}

Jump to

Keyboard shortcuts

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