cache

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package cache 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
}

An in-memory cache.

func New

func New() *Cache

New creates a new cache and returns it.

func NewWithTimeout added in v0.3.2

func NewWithTimeout(timeout time.Duration) *Cache

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

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all cache keys.

func (*Cache) Close added in v0.3.2

func (c *Cache) Close()

Close closes the cache and frees allocated resources.

func (*Cache) Delete

func (c *Cache) Delete(key any)

Delete deletes an item from the cache

func (*Cache) Exists

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

Exists reports wether a key exists

func (*Cache) Get

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

Get returns an item if it exits and it not stale. It also reports whether the item was found.

func (*Cache) Set

func (c *Cache) Set(key any, 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