GoCache is a distributed cache system implemented by Go. It is a simplified version of groupcache, which is a go version of memcached.
This project follows blog GeeCache.
GoCache supported the following features:
- Local caching and HTTP-based distributed caching.
- LRU (Least Recent Use) cache strategy.
- Avoid cache breakdown using
sync.Mutexfrom Go. - Choose nodes with consistent hashing for load balance.
- Optimize binary communication between two peers with Protobuf.
-
Basic Data Structure:
gocache/lru/lru.go: Implemented Least-Recent-Use strategy for cachegocache/byteview.go: Abstruct and insulation of byte array in cachegocache/cache.go: Wrap lru and mutex for concurrency controlgocache/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 searchgocache/consistenthash/consistenthash.go: Implemented consistent hasinggocache/peers.go: DefinePeerPickerandPeerGetterinterfacegocache/singleflight/singleflight.go: Implementedsingleflightto prevent cache breakdowngocache/gocachepb/gocachepb.proto: Use Protobuf for peers to communicate
-
Other:
run.sh: Start the server and run main.go