https://github.com/xuender/toolkit
golang toolkit
https://github.com/xuender/toolkit
Last synced: 2 months ago
JSON representation
golang toolkit
- Host: GitHub
- URL: https://github.com/xuender/toolkit
- Owner: xuender
- License: mit
- Created: 2019-08-20T08:07:37.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-24T03:39:52.000Z (over 5 years ago)
- Last Synced: 2025-02-09T19:40:57.455Z (4 months ago)
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# toolkit
golang toolkit.
## Usage
### Cache
```go
package mainimport (
"fmt"
"time""github.com/xuender/toolkit"
)func main() {
// LRU
cache := toolkit.NewCache(time.Second*3, true)
cache.Set("key1", "value1")
cache.SetByDuration("key2", "value2", time.Second)
cache.Set("key3", "value3")fmt.Println("init size:", cache.Size())
time.Sleep(time.Second * 2)
cache.Get("key3") // reset expire time.
fmt.Println("2 Second:", cache.Size())
time.Sleep(time.Second * 2)
fmt.Println("4 Second:", cache.Size())
}
```### SyncMap
```go
package mainimport (
"fmt""github.com/xuender/toolkit"
)func main() {
m := toolkit.NewSyncMap()
m.Set("key1", "value1")
m.Set("key2", "value2")fmt.Println(m.Get("key1"))
fmt.Println(m.Size())
}
```### ChMap
```go
package mainimport (
"fmt""github.com/xuender/toolkit"
)func main() {
m:= toolkit.NewChMap()
defer m.Close()
m.Set("key1", "value1")
m.Set("key2", "value2")fmt.Println(m.Get("key1"))
fmt.Println(m.Size())
}
```