Documentation
¶
Overview ¶
Package mcache provides a global memory cache which can be used to store necessary data in local memory. It uses freecache as underlying engine. For more details about freecache, please refer to https://github.com/coocood/freecache
Index ¶
- Constants
- func AverageAccessTime() int64
- func Clear()
- func Del(key string) (affected bool)
- func EntryCount() (entryCount int64)
- func EvacuateCount() (count int64)
- func ExpiredCount() (count int64)
- func Get(key string) (value []byte, err error)
- func GetInt(key string) (int, error)
- func GetIntWithExpiration(key string) (value int, expireAt uint32, err error)
- func GetString(key string) (string, error)
- func GetWithBuf(key string, buf []byte) (value []byte, err error)
- func GetWithExpiration(key string) (value []byte, expireAt uint32, err error)
- func HitCount() (count int64)
- func HitRate() float64
- func Init(memSize int, setGCPercent bool, gcPercent int)
- func IsUsable() bool
- func LookupCount() int64
- func MissCount() (count int64)
- func OverwriteCount() (overwriteCount int64)
- func ResetStatistics()
- func Set(key string, value []byte, expireSeconds int) (err error)
- func SetInt(key string, value int, expireSeconds int) error
- func SetString(key, value string, expireSeconds int) error
- func TTL(key string) (timeLeft uint32, err error)
Constants ¶
const ( // SizeKB means 1 kilobyte. SizeKB = 1024 // SizeMB means 1 megabyte. SizeMB = 1024 * SizeKB // SizeGB means 1 gigabyte. SizeGB = 1024 * SizeMB )
Variables ¶
This section is empty.
Functions ¶
func AverageAccessTime ¶
func AverageAccessTime() int64
AverageAccessTime returns the average unix timestamp when a entry being accessed. Entries have greater access time will be evacuated when it is about to be overwritten by new value.
func EntryCount ¶
func EntryCount() (entryCount int64)
EntryCount returns the number of items currently in the cache.
func EvacuateCount ¶
func EvacuateCount() (count int64)
EvacuateCount is a metric indicating the number of times an eviction occurred.
func ExpiredCount ¶
func ExpiredCount() (count int64)
ExpiredCount is a metric indicating the number of times an expire occurred.
func GetIntWithExpiration ¶
GetIntWithExpiration returns the value and expiration or a not found error.
func GetWithBuf ¶
GetWithBuf copies the value to the buf or returns not found error. This method doesn't allocate memory when the capacity of buf is greater or equal to value.
func GetWithExpiration ¶
GetWithExpiration returns the value with expiration or not found error.
func HitCount ¶
func HitCount() (count int64)
HitCount is a metric that returns number of times a key was found in the cache.
func Init ¶
Init is the first function that needs to be invoked when this package is used. It will initialized freecache according to the given parameters. memSize: the initial size of the cache in Byte. The memory will be preallocated. Example: 100 * SizeMB setGCPercent: whether to set GC percentage. gcPercent: the GC percentage to set. Memory is preallocated.If you allocate large amount of memory, you may need to set debug.SetGCPercent() to a much lower percentage to get a normal GC frequency.
func LookupCount ¶
func LookupCount() int64
LookupCount is a metric that returns the number of times a lookup for a given key occurred.
func MissCount ¶
func MissCount() (count int64)
MissCount is a metric that returns the number of times a miss occurred in the cache.
func OverwriteCount ¶
func OverwriteCount() (overwriteCount int64)
OverwriteCount indicates the number of times entries have been overriden.
func ResetStatistics ¶
func ResetStatistics()
ResetStatistics refreshes the current state of the statistics.
func Set ¶
Set sets a key, value and expiration for a cache entry and stores it in the cache. If the key is larger than 65535 or value is larger than 1/1024 of the cache size, the entry will not be written to the cache. expireSeconds <= 0 means no expire, but it can be evicted when cache is full.
Types ¶
This section is empty.