package module
Version: v0.0.0-...-ecf7504 Latest Latest

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

Go to latest
Published: Apr 13, 2018 License: MIT Imports: 5 Imported by: 0


Language: English | Русский

Go-memorycache Build Status

Manager memory key:value store/cache in Golang

How to install?

go get

How to use it?

First you must import it

import (
	memorycache ""

Init a new Cache

cache := memorycache.New("testDB", 5 * time.Minute, 10 * time.Minute)

Use it like this:

// Set cache by key
cache.Set("myKey", "My value", 5 * time.Minute)

// Get cache by key

// Check exist cache

// Delete cache by key




This section is empty.


This section is empty.


This section is empty.


type Cache

type Cache struct {
	// contains filtered or unexported fields

Cache struct cache

func New

func New(defaultExpiration, cleanupInterval time.Duration) *Cache

New. Initializing a new memory cache

func (*Cache) Copy

func (c *Cache) Copy(key string, newKey string) error

Copy copying a value from key to a newkey Return error if key eq newkey Return error if key is empty Return error if newkey is exist

func (*Cache) Delete

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

Delete cache by key Return false if key not found

func (*Cache) Exists

func (c *Cache) Exists(key string) bool

Exists check cache exist

func (*Cache) FlushAll

func (c *Cache) FlushAll() error

FlushAll delete all keys in database

func (*Cache) GC

func (c *Cache) GC()

GC Garbage Collection

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get getting a cache by key

func (*Cache) GetCount

func (c *Cache) GetCount() int

GetCount return count items, without expired

func (*Cache) GetItem

func (c *Cache) GetItem(key string) (*Item, bool)

GetItem getting item cache Second parameter returns false if cache not found or expired

func (*Cache) GetLikeKey

func (c *Cache) GetLikeKey(search string) ([]interface{}, bool)

GetLikeKey list of keys by mask findString% - start of string %findString - end of string %findString% - any occurrence of a string findString - full occurrence of a string

func (*Cache) Rename

func (c *Cache) Rename(key string, newKey string) error

Rename rename key to newkey When renaming, the value with the key is deleted Return false in key eq newkey Return false if newkey is exist

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}, duration time.Duration) error

Set setting a cache by key

func (*Cache) StartGC

func (c *Cache) StartGC() error

StartGC start Garbage Collection

type Item

type Item struct {
	Value      interface{}
	Expiration int64
	Created    time.Time
	Duration   time.Duration

Item struct cache item

func (*Item) Expire

func (i *Item) Expire() bool

Expire check cache expire Return true if cache expired

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL