memory_cache

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: MIT Imports: 3 Imported by: 0

README

MemoryCache

This project is a lock-free, thread-safe, easy-to-use memory cache module for Go that supports generics. It aims to provide efficient and concurrent data storage and retrieval.

Features

  • Support caching of any type of data using generics
  • Thread-safe and lock-free implementation for high concurrency
  • Simple and easy to use with a clean API interface
  • Support setting expiration time, and use less goroutines to clean up expired cache data

Note1: This project includes a dedicated testing branch for running test cases. Make sure to switch to that branch for testing purposes.

Note2: I can only reopen a repository due to I can't fix enhance-cache's go get bug :( .

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cleanable

type Cleanable interface {
	// contains filtered or unexported methods
}

type EnhanceCache

type EnhanceCache[K string, V any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[V any](expired time.Duration) *EnhanceCache[string, V]

func NewCacheWithEviction

func NewCacheWithEviction[V any](expired time.Duration, eviction func(key string, value V)) *EnhanceCache[string, V]

func (*EnhanceCache[K, V]) Clear

func (ec *EnhanceCache[K, V]) Clear()

func (*EnhanceCache[K, V]) DecrInt

func (ec *EnhanceCache[K, V]) DecrInt(key string, value any) (current V)

func (*EnhanceCache[K, V]) Delete

func (ec *EnhanceCache[K, V]) Delete(key string)

func (*EnhanceCache[K, V]) Get

func (ec *EnhanceCache[K, V]) Get(key string) (v V, exist bool)

func (*EnhanceCache[K, V]) IncrInt

func (ec *EnhanceCache[K, V]) IncrInt(key string, value interface{}) (current V)

IncrInt increases the int value stored under the given key by n, create new key if key does not exist. Only allow increment *int64、*int32, can multiply a float number by 100 and turn it into an integer to use it.

func (*EnhanceCache[K, V]) LoadOrStore

func (ec *EnhanceCache[K, V]) LoadOrStore(key string, value V) (V, bool)

func (*EnhanceCache[K, V]) Set

func (ec *EnhanceCache[K, V]) Set(key string, value V)

func (*EnhanceCache[K, V]) SetWithEviction

func (ec *EnhanceCache[K, V]) SetWithEviction(evictionFunc func(key string, value V))

func (*EnhanceCache[K, V]) SetWithExpiration

func (ec *EnhanceCache[K, V]) SetWithExpiration(key string, value V, expiration time.Duration)

func (*EnhanceCache[K, V]) Size

func (ec *EnhanceCache[K, V]) Size() int

type Item

type Item struct {
	Object any

	Expiration time.Time
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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