Skip to content

gkampitakis/go-tiny-lru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Tiny LRU

This go module is a replication of tiny-lru written in js.

Description

Trying to learn basic concepts of golang, implement tests and benchmarks.

Usage

go get -u github.com/gkampitakis/go-tiny-lru

Then you can use it in your code

import "github.com/gkampitakis/go-tiny-lru"

LRU.New(10,1000)
// First parameter is the max items that LRU can store
// and the second is the ttl number. 
//You can set them both to zero for no max capacity and no ttl.

Methods

New

Creates a new LRU instance.
Parameters: max int,ttl int64. max and ttl can be set to zero for specifying "infinite" capacity and no expiration time.
Returns: error,*LRU

Clear

Clears LRU and resets all values.
Parameters: -
Returns: *LRU

Delete

Deletes key from LRU if existent.
Parameters: key string
Returns: *LRU

Keys

Returns a slice containing all keys in LRU.
Note: the order of insertion is not guaranteed in the output slice as internally LRU uses maps for storing items.
Parameters: -
Returns: []string

Set

Adds a new item in LRU.
Parameters: key string,value interface{}
Returns: *LRU

Get

Returns the value of a key if existent
Parameters: key string
Returns: interface{} || nil

About

A replication of tiny-lru npm package in golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published