Skip to content

A simple groupcache-like distributed cache framework implemented by Golang.

License

Notifications You must be signed in to change notification settings

LotteWong/gingle-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gingle-cache

A simple groupcache-like distributed cache implemented by Golang.


Features

  • Cache Eviction Algorithm (LRU)
  • Stand-alone Cache
  • Distributed Cache
  • HTTP Server and Client
  • Consistent Hash (prevent cache avalanche)
  • Singleflight (prevent cache breakdown)

Quick Start

StartCacheServer

func startCacheServer(addr string, addrs []string, group *ginglecache.Group) {
  picker := ginglecache.NewHTTPPool(addr)
  picker.ConfPeers(addrs...)
  
  group.RegisterPicker(picker)
  
  log.Println("ginglecache server is running at", addr)
  log.Fatal(http.ListenAndServe(addr[7:], picker))
}

StartCacheClient

func startCacheClient(addr string, group *ginglecache.Group) {
  http.Handle("/api", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
    key := req.URL.Query().Get("key")
    view, err := group.Get(key)
    if err != nil {
      http.Error(rw, err.Error(), http.StatusInternalServerError)
      return
    }

    rw.WriteHeader(http.StatusOK)
    rw.Header().Set("Content-Type", "application/octet-stream")
    rw.Write(view.Bytes())
  }))
  
  log.Println("ginglecache client is running at", addr)
  log.Fatal(http.ListenAndServe(addr[7:], nil))
}

TODOs

  • HTTP2 Support
  • Protobuf Support
  • More Replacement Strategy
  • Distributed Unique ID Generation
  • Distributed Lock Manager
  • Goroutine and Connect Pool

About

A simple groupcache-like distributed cache framework implemented by Golang.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published