microcache

package module
v0.0.0-...-c5f3997 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: GPL-3.0 Imports: 2 Imported by: 1

README

microcache

In memory cache library for golang

GoDoc Go Report Card GoCover

How to use

Simple usage:

import (
	"fmt"

	"github.com/lpicanco/microcache"
	"github.com/lpicanco/microcache/configuration"
)

func main() {
	cache := microcache.New(configuration.DefaultConfiguration(100))
	cache.Put(42, "answer")

	value, found := cache.Get(42)
	if found {
		fmt.Printf("Value: %v\n", value)
	}

	fmt.Printf("Cache len: %v\n", cache.Len())

	cache.Invalidate(42)
}

Custom options:


import (
	"fmt"
	"time"

	"github.com/lpicanco/microcache"
	"github.com/lpicanco/microcache/configuration"
)

func main() {
	cache := microcache.New(configuration.Configuration{
		MaxSize:           10000,
		ExpireAfterWrite:  1 * time.Hour,
		ExpireAfterAccess: 10 * time.Minute,
		CleanupCount:      5,
	})
	cache.Put(42, "answer")

	value, found := cache.Get(42)
	if found {
		fmt.Printf("Value: %v\n", value)
	}

	fmt.Printf("Cache len: %v\n", cache.Len())

	cache.Invalidate(42)
}

Documentation

Overview

Package microcache is the core package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Put a item to the cache
	Put(key interface{}, value interface{})
	// Get a item from the cache
	Get(key interface{}) (value interface{}, found bool)
	// Remove a item from the cache.
	Invalidate(key interface{}) (found bool)
	// Len of the cache
	Len() int
	// Close the cache
	Close()
}

Cache interface

func New

func New(config configuration.Configuration) Cache

New returns a new cache

Directories

Path Synopsis
examples
custom command
simple command

Jump to

Keyboard shortcuts

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