Skip to content

a-hilaly/memcache

Repository files navigation

memcache

CircleCI codecov

Zero dependencies memcache key|value store library. It supports multi threaded programs and offer an easy to use auditing properties.

Features

  • Zero dependencies
  • Thread safe cache & store objects
  • Audit utilities to delete expired items

Usage

go get -u github.com/a-hilaly/memcache

Example

package main

import (
   "fmt"
   "time"

   "github.com/a-hilaly/memcache"
)

func main() {
   // create new cache
   mc := memcache.New(10, 10, 2*time.Second)

   // create audit fn
   auditFn := memcache.NewAuditorFunc(time.Millisecond*100, time.Millisecond*500)

   // start auditing
   done, stop := auditFn(mc)

   // put some key & value
   mc.Put("key1", "value")
   
   time.Sleep(time.Second * 1)
   // put key2
   mc.Put("key2", "value2")

   time.Sleep(time.Second * 1)

   // send stop signal to the goroutine auditing the cache
   stop <- struct{}{}
   
   // wait for it to finish
   <-done

   // check keys values
   fmt.Println(mc.Get("key"))  // expired
   fmt.Println(mc.Get("key2")) // still exists
}

}

Benchmarks

see BENCHMARKS.md

Releases

No releases published

Packages

No packages published

Languages