项目作者: A-Hilaly

项目描述 :
A small memcache implementation Go
高级语言: Go
项目地址: git://github.com/A-Hilaly/memcache.git
创建时间: 2018-04-27T16:33:58Z
项目社区:https://github.com/A-Hilaly/memcache

开源协议:Apache License 2.0

下载


memcache

CircleCI codecov

Zero dependencies memcache key|value store library. It supports multi threaded programs and offer an easy to use auditing properties.

Features

  • Zero dependencies
  • Thread safe cache & store objects
  • Audit utilities to delete expired items

Usage

  1. go get -u github.com/a-hilaly/memcache

Example

  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/a-hilaly/memcache"
  6. )
  7. func main() {
  8. // create new cache
  9. mc := memcache.New(10, 10, 2*time.Second)
  10. // create audit fn
  11. auditFn := memcache.NewAuditorFunc(time.Millisecond*100, time.Millisecond*500)
  12. // start auditing
  13. done, stop := auditFn(mc)
  14. // put some key & value
  15. mc.Put("key1", "value")
  16. time.Sleep(time.Second * 1)
  17. // put key2
  18. mc.Put("key2", "value2")
  19. time.Sleep(time.Second * 1)
  20. // send stop signal to the goroutine auditing the cache
  21. stop <- struct{}{}
  22. // wait for it to finish
  23. <-done
  24. // check keys values
  25. fmt.Println(mc.Get("key")) // expired
  26. fmt.Println(mc.Get("key2")) // still exists
  27. }
  28. }

Benchmarks

see BENCHMARKS.md