8000 GitHub - yogyrahmawan/bcache · GitHub
[go: up one dir, main page]

Skip to content
yogyrahmawanPublic
forked from iwanbk/bcache

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

 
 

Repository files navigation

bcache

godoc Build Status codecov Go Report Card

A Go Library to create distributed in-memory cache.

It uses Gossip Protocol for data synchronization between peers.

Features

  • LRU cache with configurable maximum keys
  • Eventual Consistency synchronization between peers
  • Data are replicated to all peers
  • cache filling mechanism. When the cache of the given key is not exist, bcache coordinates cache fills such that only one call populates the cache to avoid thundering herd or cache stampede

Why using it

  • if extra network hops needed by external caches like redis or memcached is not acceptable for you
  • you only need cache with simple Set & Get operation
  • you have enough RAM to hold the cache data

Credits

Quick Start

In server 1

bc, err := New(Config{
	PeerID:     1,
	ListenAddr: "192.168.0.1:12345",
	Peers:      nil,
	MaxKeys:    1000,
	Logger:     logrus.New(),
})
if err != nil {
    log.Fatalf("failed to create cache: %v", err)
}
bc.Set("my_key", "my_val")

In server 2

bc, err := New(Config{
	PeerID:     2,
	ListenAddr: "192.168.0.2:12345",
	Peers:      []string{"192.168.0.1:12345"},
	MaxKeys:    1000,
	Logger:     logrus.New(),
})
if err != nil {
    log.Fatalf("failed to create cache: %v", err)
}
bc.Set("my_key2", "my_val2")

In server 3

bc, err := New(Config{
	PeerID:     3,
	ListenAddr: "192.168.0.3:12345",
	Peers:      []string{"192.168.0.1:12345"},
	MaxKeys:    1000,
	Logger:     logrus.New(),
})
if err != nil {
    log.Fatalf("failed to create cache: %v", err)
}
val, exists := bc.Get("my_key2")

Cache filling

c, err := New(Config{
	PeerID:     3,
	ListenAddr: "192.168.0.3:12345",
	Peers:      []string{"192.168.0.1:12345"},
	MaxKeys:    1000,
	Logger:     logrus.New(),
})
if err != nil {
    log.Fatalf("failed to create cache: %v", err)
}
val, exists,err  := bc.GetWithFiller("my_key2",func(key string) (string, int64, error) {
                // get value from database
                 .....
                //
				return value, 0, nil
			})

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0