Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/midaef/custom-memory-cache
C.M.C it's simple implementation memory cache [key:value] in GO with time to live
https://github.com/midaef/custom-memory-cache
cache data go golang memory midaef
Last synced: 29 days ago
JSON representation
C.M.C it's simple implementation memory cache [key:value] in GO with time to live
- Host: GitHub
- URL: https://github.com/midaef/custom-memory-cache
- Owner: midaef
- License: mit
- Created: 2020-10-01T04:39:38.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T03:36:45.000Z (about 4 years ago)
- Last Synced: 2024-08-03T23:23:58.847Z (4 months ago)
- Topics: cache, data, go, golang, memory, midaef
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-repositories - custom-memory-cache
README
# Custom-Memory-Cache
## Install
```
go get github.com/midaef/custom-memory-cache
```## Example
```go
package testsimport (
"log""github.com/midaef/custom-memory-cache/cache"
)func main() {
// Create new cache function takes two arguments.
// First cache size and second garbage collerctor interval.
// gcInterval it's time between clearing the cache
// if set gcInterval - 0 then garbage collerctor won't work
cache := cache.NewCache(16, 0)// Write data with key to cache
cache.Write("token", "1234", 0)// Read data from cache by key
data, err := cache.Read("token")
if err != nil {
log.Println(err)
}
log.Println(data)// Read all data from cache
mapData, err := cache.ReadAll()
if err != nil {
log.Println(err)
}
log.Println(mapData)// Delete element from cache by key
err = cache.Delete("token")
if err != nil {
log.Println(err)
}
```
## Benchmark tests
```
goos: windows
goarch: 386
pkg: github.com/midaef/custom-memory-cache/tests
BenchmarkWrite-4 6519778 188 ns/op
BenchmarkRead-4 23077322 53.4 ns/op
BenchmarkReadWrite-4 3972715 297 ns/op
BenchmarkWriteDelete-4 4411705 270 ns/op
PASS
ok github.com/midaef/custom-memory-cache/tests 6.288s
```
## License
[MIT](https://github.com/midaef/custom-memory-cache/blob/master/LICENSE)