mem

package
v0.0.0-...-ba70d0f Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package mem implements a memory cache

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache implement a memory cache

func New

func New[T any](defaultExpr time.Duration, cleanInterval time.Duration) *Cache[T]

New create instance memory cache

Parameters:

  • defaultExpr is a time to live of items
  • cleanInterval is cleanup cycle for expired items

func NewDefault

func NewDefault[T any]() *Cache[T]

NewDefault create new memory cache with, default expr is 1 minute and cleanup cycle is 1 minute

func (*Cache[T]) Del

func (c *Cache[T]) Del(k string)

Del used to delete key from memory

func (*Cache[T]) Get

func (c *Cache[T]) Get(k string) (T, bool)

Get used to get value of key

Returns:

  • result T is result data of Get function
  • found bool is a second value of Get, true when value is found, false when value is not found

func (*Cache[T]) List

func (c *Cache[T]) List() ([]T, bool)

List used to list all items in cache

func (*Cache[T]) Set

func (c *Cache[T]) Set(k string, v T)

Set used to set key with value into memory

func (*Cache[T]) SetWithTTL

func (c *Cache[T]) SetWithTTL(k string, v T, ttl time.Duration)

SetWithTTL used to set key with value with time to live

Jump to

Keyboard shortcuts

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