https://github.com/gkampitakis/go-tiny-lru
A replication of tiny-lru npm package in golang
https://github.com/gkampitakis/go-tiny-lru
go-module golang lru-cache
Last synced: 11 days ago
JSON representation
A replication of tiny-lru npm package in golang
- Host: GitHub
- URL: https://github.com/gkampitakis/go-tiny-lru
- Owner: gkampitakis
- License: mit
- Created: 2020-09-25T20:41:05.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T17:36:19.000Z (over 5 years ago)
- Last Synced: 2023-03-06T06:37:13.123Z (over 3 years ago)
- Topics: go-module, golang, lru-cache
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Tiny LRU
This go module is a replication of [tiny-lru](https://www.npmjs.com/package/tiny-lru) written in js.
## Description
Trying to learn basic concepts of golang, implement tests and benchmarks.
## Usage
```bash
go get -u github.com/gkampitakis/go-tiny-lru
```
Then you can use it in your code
```go
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`