Popularity
3.5
Growing
Activity
3.7
Growing
49
3
8

Programming language: Go
Tags: Data Structures    

go-mcache alternatives and similar packages

Based on the "Data Structures" category

Do you think we are missing an alternative of go-mcache or a related project?

Add another 'Data Structures' Package

README

MCache library

Build Status Go Report Card GoDoc

go-mcache - this is a fast key:value storage. Its major advantage is that, being essentially a thread-safe .

map[string]interface{}

with expiration times, it doesn't need to serialize, and quick removal of expired keys.

Installation

~ $ go get -u github.com/OrlovEvgeny/go-mcache

Example a Pointer value (vary fast method)

type User struct {
    Name string
    Age  uint
    Bio  string
}

func main() {
    //Start mcache instance
    MCache = mcache.New()

    //Create custom key
    key := "custom_key1"
    //Create example struct
    user := &User{
        Name: "John",
        Age:  20,
        Bio:  "gopher 80 lvl",
    }

    //args - key, &value, ttl (or you need never delete, set ttl is mcache.TTL_FOREVER)
    err := MCache.Set(key, user, time.Minute*20)
    if err != nil {
        log.Fatal(err)
    }

    if data, ok := MCache.Get(key); ok {
        objUser:= data.(*User)
        fmt.Printf("User name: %s, Age: %d, Bio: %s\n", objUser.Name, objUser.Age, objUser.Bio)         
    }
}

Performance Benchmarks

goos: darwin
goarch: amd64
BenchmarkWrite-4          200000              7991 ns/op 
BenchmarkRead-4          1000000              1716 ns/op 
BenchmarkRW-4             300000              9894 ns/op

What should be done

  • [x] the possibility of closing
  • [x] r/w benchmark statistics
  • [ ] rejection of channels in safeMap in favor of sync.Mutex (there is an opinion that it will be faster)

License:

[MIT](LICENSE)


*Note that all licence references and agreements mentioned in the go-mcache README section above are relevant to that project's source code only.