Skip to content

miguelbemartin/lru-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LRU Cache Go Package

Implementation of LRU Cache in Go

Go Report Card Build Status codecov MIT licensed

Getting Started

Prerequisites

  • Go 1.10+

Installation

Run into the terminal the next command

go get github.com/miguelbemartin/lru-cache

Usage

package main

import (
	"fmt"

	lrucache "github.com/miguelbemartin/lru-cache"
)

func main() {

	// Init the LRU Cache client
	myCache, err := lrucache.NewLRUCache(2)
	if err != nil {
		panic("Error")
	}

	// Add a key and value to cache
	err = myCache.Set("my-key", "my value")
	if err != nil {
		panic("Error adding a new element to cache")
	}

	// Fetch value by key
	value, err := myCache.Get("my-key")
	if err != nil {
		panic("Error fetching new value from cache")
	}

	// Clean cache
	err = myCache.Prune()
	if err != nil {
		panic("Error cleaning the cache")
	}

	// Print the value
	fmt.Println("My value is: ", value)
}

Run the tests

go test ./... -v

Contributing

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

Implementation of LRU Cache in Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages