Skip to content

hslam/lru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lru

PkgGoDev Build Status codecov Go Report Card LICENSE

Package lru implements an LRU cache.

Get started

Install

go get github.com/hslam/lru

Import

import "github.com/hslam/lru"

Usage

Example

package main

import (
	"fmt"
	"github.com/hslam/lru"
)

func main() {
	var capacity = 1024
	var free lru.Free = func(key, value interface{}) {}
	l := lru.New(capacity, free)
	key := 1
	value := "Hello world"
	cost := len(value)
	r := l.Set(key, value, cost)
	r.Done()
	if v, r, ok := l.Get(key); ok {
		fmt.Println(v)
		r.Done()
	}
	l.Remove(key)
	l.Reset()
}

Output

Hello world

License

This package is licensed under a MIT license (Copyright (c) 2021 Meng Huang)

Author

lru was written by Meng Huang.

About

Package lru implements an LRU cache.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages