项目作者: lpicanco

项目描述 :
In memory cache library for golang
高级语言: Go
项目地址: git://github.com/lpicanco/microcache.git
创建时间: 2019-06-17T16:44:13Z
项目社区:https://github.com/lpicanco/microcache

开源协议:GNU General Public License v3.0

下载


microcache

In memory cache library for golang

GoDoc
Go Report Card
GoCover

How to use

Simple usage:

  1. import (
  2. "fmt"
  3. "github.com/lpicanco/microcache"
  4. "github.com/lpicanco/microcache/configuration"
  5. )
  6. func main() {
  7. cache := microcache.New(configuration.DefaultConfiguration(100))
  8. cache.Put(42, "answer")
  9. value, found := cache.Get(42)
  10. if found {
  11. fmt.Printf("Value: %v\n", value)
  12. }
  13. fmt.Printf("Cache len: %v\n", cache.Len())
  14. cache.Invalidate(42)
  15. }

Custom options:

  1. import (
  2. "fmt"
  3. "time"
  4. "github.com/lpicanco/microcache"
  5. "github.com/lpicanco/microcache/configuration"
  6. )
  7. func main() {
  8. cache := microcache.New(configuration.Configuration{
  9. MaxSize: 10000,
  10. ExpireAfterWrite: 1 * time.Hour,
  11. ExpireAfterAccess: 10 * time.Minute,
  12. CleanupCount: 5,
  13. })
  14. cache.Put(42, "answer")
  15. value, found := cache.Get(42)
  16. if found {
  17. fmt.Printf("Value: %v\n", value)
  18. }
  19. fmt.Printf("Cache len: %v\n", cache.Len())
  20. cache.Invalidate(42)
  21. }