lru

package module
v0.0.0-...-eb41792 Latest Latest
Warning

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

Go to latest
Published: May 16, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

README

lru-go

lru implementation in golang

API docs

  1. First init a cache with size
c, er := lru.New(<size>)

c, the cache instance er, if cache creation had any error

  1. Add to cache
wasThereAnyEviction = c.Add(<any_string_value>)

wasThereAnyEviction, (bool) that tells whether there was an eviction for adding cache

  1. Query to cache
val, ok = c.Query(<any_string_value>)

val, the value against the query (defaults to empty string "", if in case query not found) ok, if query has corresponding value or not

dir structure

  • main.go -> the lru cache
  • main_test.go -> the test files

dependencies

  • go 1.14+

dev dependencies

  • make 4.1+
  • inotifywait 3.14

testing

All modules has their *_test files as UT. run tests with

make test

TODO

  • complete testing with full coverage
  • use mutex locks for concurrency protection
  • use separate key value for storing into in cache
  • use persistent storage
  • more to discuss

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func New

func New(cp int) (*Cache, error)

create cache

func (*Cache) Add

func (c *Cache) Add(val string) bool

add to cache

func (*Cache) Query

func (c *Cache) Query(qr string) (val string, ok bool)

query to cache

Jump to

Keyboard shortcuts

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