ThmsLiang / GoCache

A Distributed Cache System implemented with Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoCache

GoCache is a distributed cache system implemented by Go. It is a simplified version of groupcache, which is a go version of memcached.

Credit

This project follows blog GeeCache.

Features

GoCache supported the following features:

  • Local caching and HTTP-based distributed caching.
  • LRU (Least Recent Use) cache strategy.
  • Avoid cache breakdown using sync.Mutex from Go.
  • Choose nodes with consistent hashing for load balance.
  • Optimize binary communication between two peers with Protobuf.

Structure

  • Basic Data Structure:

    • gocache/lru/lru.go: Implemented Least-Recent-Use strategy for cache
    • gocache/byteview.go: Abstruct and insulation of byte array in cache
    • gocache/cache.go: Wrap lru and mutex for concurrency control
    • gocache/gocache.go: Interact with outside, main procedure to get and update cache
  • HTTP related:

    • gocache/http.go: Define a http pool and parse http request for key search
    • gocache/consistenthash/consistenthash.go: Implemented consistent hasing
    • gocache/peers.go: Define PeerPicker and PeerGetter interface
    • gocache/singleflight/singleflight.go: Implemented singleflight to prevent cache breakdown
    • gocache/gocachepb/gocachepb.proto: Use Protobuf for peers to communicate
  • Other:

    • run.sh: Start the server and run main.go

About

A Distributed Cache System implemented with Golang


Languages

Language:Go 98.1%Language:Shell 1.9%