memcache

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: BSD-3-Clause Imports: 2 Imported by: 2 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

memcache

Memory cache with benefits

GoDoc

Features

  • Key expiration
  • Redis Sorted set emulation
  • Lock/Unlock with key

Documentation

Index

Constants

View Source
const (
	LockWithKeyDefaultTimeout = 10 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheType

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

CacheType - cache structure with bound methods

func New

func New(logger Logger) (memCache *CacheType)

New - prepare and populate memcache instance

func (*CacheType) Add

func (mc *CacheType) Add(key string, value interface{}) (itemID int64)

Add - add item to cache and return resulting item ID

func (*CacheType) Cache

func (mc *CacheType) Cache() (cache map[string]*ValueType)

Cache - return whole cache contents

func (*CacheType) Delete

func (mc *CacheType) Delete(key string)

Delete - removes item from cache

func (*CacheType) Evictor

func (mc *CacheType) Evictor()

Evictor - background goroutine that periodically purges expired keys

func (*CacheType) Get

func (mc *CacheType) Get(key string) (value interface{}, ok bool)

Get - fetch item from cache with ok indicating status of the operation

func (*CacheType) GetByID

func (mc *CacheType) GetByID(itemID int64) (item interface{})

GetByID - fetch item from cache based on item ID. Return nil otherwise

func (*CacheType) GetEx added in v1.0.1

func (mc *CacheType) GetEx(key string) (*ValueType, bool)

GetEx - get key/value pair with expiration

func (*CacheType) Len

func (mc *CacheType) Len() (cacheSize int64)

Len - returns cache length

func (*CacheType) LenSafe

func (mc *CacheType) LenSafe() (cacheSize int64)

LenSafe - same as Len() but with read lock

func (*CacheType) LockWithKey added in v1.0.2

func (mc *CacheType) LockWithKey(key string)

func (*CacheType) Set

func (mc *CacheType) Set(key string, value interface{})

Set - set key/value pair without expiration

func (*CacheType) SetEx

func (mc *CacheType) SetEx(key string, value interface{}, expires int64)

SetEx - set key/value pair with expiration

func (*CacheType) SetLockWithKeyTimeout added in v1.0.2

func (mc *CacheType) SetLockWithKeyTimeout(timeout time.Duration)

func (*CacheType) Stop

func (mc *CacheType) Stop()

Stop - run some cleaning chores during shutdown

func (*CacheType) UnlockWithKey added in v1.0.2

func (mc *CacheType) UnlockWithKey(key string)

func (*CacheType) UnsafeDelete

func (mc *CacheType) UnsafeDelete(key string)

UnsafeDelete - removes item from cache

type Logger

type Logger interface {
	Printf(fmt string, args ...interface{})
	Debug(s ...interface{})
}

Logger - memcache logger interface. Can be stdlib log, logrus etc

type ValueType

type ValueType struct {
	Value    interface{}
	Expires  int64
	MetaData string
}

ValueType - memcache item

Jump to

Keyboard shortcuts

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