mcache

package module
v0.0.0-...-24f737c Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: MIT Imports: 5 Imported by: 1

README

go-mcache

Package mcache provides a thread-safe in-memory cache, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-mcache

GoDoc

Examples

Here is an example of using mcache:

import "github.com/reiver/go-mcache"

// ...

var defaultTTL time.Duration = 5 * time.Minute

cache := mcache.NewTTL[Type](defaultTTL)
if nil == cache {
	return errors.New("nil cache")
}

// ...

cache.Set(key, value)

// ...

val, found := cache.Get(name)

Import

To import package mcache use import code like the following:

import "github.com/reiver/go-mcache"

Installation

To install package mcache do the following:

GOPROXY=direct go get github.com/reiver/go-mcache

Author

Package mcache was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cacher

type Cacher[T any] interface {
	Get(name string) (value T, found bool)
	Set(name string, value T) (previous T, found bool)

	// Span returns the total of elements in Cacher include expired elements that have NOT been deleted yet.
	// Thus Span talks more about member usage.
	// Although what Span returns is a count rather than the number of bytes.
	Span() int

	Unset(name string) (previous T, found bool)
	Vacuum()
}

Cacher represents something that caches.

type TTLCacher

type TTLCacher[T any] interface {
	Cacher[T]
	GetTTL(name string) (ttl time.Duration, found bool)
	TTLSet(ttl time.Duration, name string, value T) (previous T, found bool)
}

TTLCacher represents something that caches with a TTL (time-to-live).

func NewTTL

func NewTTL[T any](defaultTTL time.Duration) TTLCacher[T]

NewTTL returns a new TTLCacher.

Jump to

Keyboard shortcuts

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