mcache

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: MIT Imports: 3 Imported by: 0

README ΒΆ

go-mcache

In-memory cache manager in Golang, key/value data storage with storage duration

Install

go get github.com/Sagleft/go-mcache

Usage example

Import package

import (
	mcache "github.com/Sagleft/go-mcache"
)

Init cache

// Create a cache with a default lifetime of 5 minutes and delete expired caches every 10 minutes
cache := memorycache.New(5 * time.Minute, 1 * time.Minute)

Usage

// Install the cache with the key "myKey" and a lifetime of 5 minutes
cache.Set("myKey", "My value", 5 * time.Minute)

// Get the cache with the "myKey" key
i := cache.Get("myKey")

image

🌐 Telegram

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type Cache ΒΆ

type Cache struct {
	sync.RWMutex
	// 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) Delete ΒΆ

func (c *Cache) Delete(key interface{}) error

Delete cache by key Return false if key not found

func (*Cache) GC ΒΆ

func (c *Cache) GC()

GC Garbage Collection

func (*Cache) Get ΒΆ

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

Get getting a cache by key

func (*Cache) GetItemsCount ΒΆ added in v1.0.6

func (c *Cache) GetItemsCount() int

GetItemsCount - get cache items count

func (*Cache) Set ΒΆ

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

Set setting a cache by key

func (*Cache) StartGC ΒΆ

func (c *Cache) StartGC()

StartGC start Garbage Collection

type Item ΒΆ

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

Item struct cache item

Jump to

Keyboard shortcuts

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