cache

package
v0.0.0-...-85b91c5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 12 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCache

func GetCache() mc.Cache

GetCache returns the currently configured cache

func GetInt

func GetInt(key string, getFunc func() (int, error)) (int, error)

GetInt returns key value from cache with callback when no key exists in cache

func GetInt64

func GetInt64(key string, getFunc func() (int64, error)) (int64, error)

GetInt64 returns key value from cache with callback when no key exists in cache

func GetString

func GetString(key string, getFunc func() (string, error)) (string, error)

GetString returns the key value from cache with callback when no key exists in cache

func NewContext

func NewContext() error

NewContext start cache service

func Remove

func Remove(key string)

Remove key from cache

Types

type MemoryItem

type MemoryItem struct {
	Val     interface{}
	Created int64
	Timeout int64
}

MemoryItem represents a memory cache item.

type RedisCacher

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

RedisCacher represents a redis cache adapter implementation.

func (*RedisCacher) Decr

func (c *RedisCacher) Decr(key string) error

Decr decreases cached int-type value by given key as a counter.

func (*RedisCacher) Delete

func (c *RedisCacher) Delete(key string) error

Delete deletes cached value by given key.

func (*RedisCacher) Flush

func (c *RedisCacher) Flush() error

Flush deletes all cached data.

func (*RedisCacher) Get

func (c *RedisCacher) Get(key string) interface{}

Get gets cached value by given key.

func (*RedisCacher) Incr

func (c *RedisCacher) Incr(key string) error

Incr increases cached int-type value by given key as a counter.

func (*RedisCacher) IsExist

func (c *RedisCacher) IsExist(key string) bool

IsExist returns true if cached value exists.

func (*RedisCacher) Ping

func (c *RedisCacher) Ping() error

Ping tests if the cache is alive.

func (*RedisCacher) Put

func (c *RedisCacher) Put(key string, val interface{}, expire int64) error

Put puts value (string type) into cache with key and expire time. If expired is 0, it lives forever.

func (*RedisCacher) StartAndGC

func (c *RedisCacher) StartAndGC(opts cache.Options) error

StartAndGC starts GC routine based on config string settings. AdapterConfig: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180,hset_name=MacaronCache,prefix=cache:

type TwoQueueCache

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

TwoQueueCache represents a LRU 2Q cache adapter implementation

func (*TwoQueueCache) Decr

func (c *TwoQueueCache) Decr(key string) error

Decr decreases cached int-type value by given key as a counter.

func (*TwoQueueCache) Delete

func (c *TwoQueueCache) Delete(key string) error

Delete deletes cached value by given key.

func (*TwoQueueCache) Flush

func (c *TwoQueueCache) Flush() error

Flush deletes all cached data.

func (*TwoQueueCache) Get

func (c *TwoQueueCache) Get(key string) interface{}

Get gets cached value by given key.

func (*TwoQueueCache) Incr

func (c *TwoQueueCache) Incr(key string) error

Incr increases cached int-type value by given key as a counter.

func (*TwoQueueCache) IsExist

func (c *TwoQueueCache) IsExist(key string) bool

IsExist returns true if cached value exists.

func (*TwoQueueCache) Ping

func (c *TwoQueueCache) Ping() error

Ping tests if the cache is alive.

func (*TwoQueueCache) Put

func (c *TwoQueueCache) Put(key string, val interface{}, timeout int64) error

Put puts value into cache with key and expire time.

func (*TwoQueueCache) StartAndGC

func (c *TwoQueueCache) StartAndGC(opts mc.Options) error

StartAndGC starts GC routine based on config string settings.

type TwoQueueCacheConfig

type TwoQueueCacheConfig struct {
	Size        int     `ini:"SIZE" json:"size"`
	RecentRatio float64 `ini:"RECENT_RATIO" json:"recent_ratio"`
	GhostRatio  float64 `ini:"GHOST_RATIO" json:"ghost_ratio"`
}

TwoQueueCacheConfig describes the configuration for TwoQueueCache

Jump to

Keyboard shortcuts

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