Skip to content

LRU cache go package implementation with generic support. this package is modification of https://github.com/projectdiscovery/expirablelru and container/list packages

License

Notifications You must be signed in to change notification settings

aaabhilash97/lru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package is modification of https://github.com/projectdiscovery/expirablelru and "container/list" packages. Only difference is added generics support, so we can avoid type assertion.

LRU cache package for golang with expiry support using go generics.

How to install package

go get -u github.com/aaabhilash97/lru

Usage

package main

import (
	"log"
	"time"

	"github.com/aaabhilash97/lru"
)

func evictCallback(key string, value string) {
	log.Println(key, value)
}

func main() {
	var cache *lru.Cache[string, string]
	cache = lru.NewLRU(100, evictCallback, time.Minute*30, time.Minute*45)

	_ = cache.Add("key", "text")
	text, ok := cache.Get("key")
	log.Println(text, ok)
}

About

LRU cache go package implementation with generic support. this package is modification of https://github.com/projectdiscovery/expirablelru and container/list packages

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages