memcache

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package memcache implements a simple in-memory cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache represents an in-memory cache.

func New

func New() *Cache

New creates a new cache with default timeout and returns it.

Users can close the cache to free allocated resources when the cache is no longer needed.

func NewWithTimeout

func NewWithTimeout(cleanUpTimeout time.Duration) *Cache

NewWithTimeout creates a new cache with a specific timeout for the regular clean-up and returns it.

A timeout of 0 disables the automatic clean-up and users then need to start clean-up manually.

When automatic clean-up is enabled users can close the cache to free allocated resources when the cache is no longer needed.

func (*Cache) CleanUp

func (c *Cache) CleanUp()

CleanUp removes all expired items.

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items.

func (*Cache) Close

func (c *Cache) Close()

Close closes the cache and frees allocated resources.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete deletes an item.

func (*Cache) Exists

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

Exists reports whether an item exists. Expired items do not exist.

func (*Cache) Get

func (c *Cache) Get(key string) (any, bool)

Get returns an item that exists and is not expired. It also reports whether the item was found.

func (*Cache) Set

func (c *Cache) Set(key string, value any, timeout time.Duration)

Set stores an item in the cache.

If an item with the same key already exists it will be overwritten. An item with timeout = 0 never expires

Jump to

Keyboard shortcuts

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