vegamcache

package module
v0.0.0-...-4a9a08c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

vegamcache

vegamcache is a distributed in-memory cache built using gossip protocol for golang.

what is the difference between other distributed cache service?

In vegamcache, network calls are not used for retriving data for each Get. Instead data will be replicated across the node using gossip in backgroud.

Expired keys are removed on gossip instead of having a seperate GC.

seri why ?

Go is fun. I learned lot of thing regarding distributed system and also I'm jobless. Looking for internship. If anyone interested, do ping me at rbalajis25@gmail.com

Drawback

  • Can be used only in golang
  • Consumes lot of main memory.(If you worring about memory, folks at google did a good job on group cache)

Need to be done

  • sharding the cache instead of storing it in a single hashmap
  • benchmarking against other cache service

Example

Clustered Cache

vg, err := vegamcache.NewVegam(&vegamcache.VegamConfig{Port: 8087,
            PeerName: "00:00:00:00:00:01",
            Peers: []string{"remoteip1:port","remoteip2:port"},
			Logger:   log.New(ioutil.Discard, "", 0)})
vg.Start()
defer vg.Stop()
if err != nil {
    panic(err)
}
vg.Put("foo", "bar", time.Second*200)
val, exist := vg.Get("foo")
if exist {
    fmt.Println(val)
}

Single Node Cache

vg := vegamcache.NewCache()
vg.Put("foo", "bar", time.Second*200)
val, exist := vg.Get("foo")
if exist {
    fmt.Println(val)
}

Contribution

Feel free to send PR. :)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenServer

func ListenServer(v *Vegam, port string) error

func NewCache

func NewCache() *externalCache

Types

type UpdateRequest

type UpdateRequest struct {
	Peers []string `json:"peers"`
}

type UpdateResponse

type UpdateResponse struct {
	Updated          bool   `json:"updated"`
	ErrorDescription string `json:"error_description"`
}

type Value

type Value struct {
	Data      interface{}
	LastWrite int64
	Expiry    int64
}

type Vegam

type Vegam struct {
	// contains filtered or unexported fields
}

func NewVegam

func NewVegam(vc *VegamConfig) (*Vegam, error)

func (*Vegam) Get

func (v *Vegam) Get(key string) (val interface{}, exist bool)

func (*Vegam) Put

func (v *Vegam) Put(key string, val interface{}, expiry time.Duration)

func (*Vegam) Start

func (v *Vegam) Start()

func (*Vegam) Stop

func (v *Vegam) Stop()

type VegamConfig

type VegamConfig struct {
	Port     int
	Channel  string
	Password string
	NickName string
	Peers    []string
	PeerName string
	Host     string
	Logger   *log.Logger
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL