memcache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package memcache provides a simple in-memory cache with per-item TTL, backed by patrickmn/go-cache.

Use DefaultTtl for the cache's default expiration and Forever for items that never expire.

Index

Examples

Constants

View Source
const (
	DefaultTtl = 0
	Forever    = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MemCache

type MemCache interface {
	// Get retrieves item by key
	Get(key string) (interface{}, bool)
	// Set sets item with key and ttl
	// If the duration is 0, the cache's default expiration time is used.
	// If it is -1, the item never expires.
	Set(key string, v interface{}, ttl time.Duration)
	// Delete deletes key
	Delete(key string)
}

MemCache provides in simple memory cache with ttl

Example
package main

import (
	"fmt"

	"github.com/zloevil/jet/memcache"
)

func main() {
	c := memcache.NewMemCache()
	c.Set("greeting", "hello", memcache.DefaultTtl)

	v, ok := c.Get("greeting")
	fmt.Println(v, ok)

	_, ok = c.Get("missing")
	fmt.Println(ok)
}
Output:
hello true
false

func NewMemCache

func NewMemCache() MemCache

Jump to

Keyboard shortcuts

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