cache

module
v0.0.0-...-6c0920c Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT

README

Concurrent LRU Cache in Go

This package provides a thread-safe implementation of Least Recently Used (LRU) cache.

Usage

package main

import (
	"fmt"
	"time"

	"github.com/sorushp/cache/pkg/cache"
)

func main() {
	// Create a new cache instance
	myCache := cache.NewCache[string]() // Replace string with your value type

	// Set and Get values
	myCache.Set("key1", "value1", 10*time.Second) // Set key1 with value1 and TTL of 10 seconds
	value, found := myCache.Get("key1")
	if found {
		fmt.Println("Retrieved value: ", value)
	}
}

Test

Read Makefile to test and benchmark the package:

make # all

make test
make coverage
make benchmark
make pprof-cpu
make pprof-mem
make clean

Directories

Path Synopsis
pkg
cache
Package cache provides a concurrent LRU cache.
Package cache provides a concurrent LRU cache.

Jump to

Keyboard shortcuts

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