Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vvatanabe/expiremap
synchronization map with expiration date (extended sync.Map)
https://github.com/vvatanabe/expiremap
Last synced: 24 days ago
JSON representation
synchronization map with expiration date (extended sync.Map)
- Host: GitHub
- URL: https://github.com/vvatanabe/expiremap
- Owner: vvatanabe
- License: mit
- Created: 2020-03-27T09:10:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-28T22:31:54.000Z (about 4 years ago)
- Last Synced: 2024-05-21T12:37:59.530Z (6 months ago)
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# expiremap ![](https://github.com/vvatanabe/expiremap/workflows/Go/badge.svg)
synchronization map with expiration date (extended sync.Map)
## Description
`expiremap.Map` provides a func that is compatible with `sync.Map` and an extended func.
## Installation
This package can be installed with the go get command:
```
$ go get github.com/vvatanabe/expiremap
```## Usage
```go
package mainimport (
"fmt"
"time""github.com/vvatanabe/expiremap"
)func main() {
var m expiremap.Map// SetDefaultExpire sets default expiration for value in Map.
m.SetDefaultExpire(time.Second / 2)// Store sets the value for a key with default expiration.
m.Store("key1", "foo")// Load returns the value in expiration stored in the map for a key,
// or nil if no value is present.
v, ok := m.Load("key1")
if !ok {
return
}
fmt.Println("key1:", v)// Store with expire sets the value for a key with expiration.
m.Store("key2", "bar", expiremap.Expire(time.Second / 2))
v, ok = m.Load("key2")
if !ok {
return
}
fmt.Println("key2:", v)// Wait for expiration
time.Sleep(time.Second)_, ok = m.Load("key1")
if !ok {
fmt.Println("key1 expired")
}
_, ok = m.Load("key2")
if !ok {
fmt.Println("key2 expired")
}
}
```## Bugs and Feedback
For bugs, questions and discussions please use the Github Issues.