Skip to content

Instantly share code, notes, and snippets.

@sakti
Created August 30, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakti/b91aa2119ce10ad1faa307605f080a49 to your computer and use it in GitHub Desktop.
Save sakti/b91aa2119ce10ad1faa307605f080a49 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"os"
"runtime/debug"
"time"
"github.com/allegro/bigcache"
humanize "github.com/dustin/go-humanize"
)
func main() {
cfg := bigcache.Config{
Shards: 1024,
LifeWindow: 30 * time.Minute,
MaxEntriesInWindow: 1000 * 10 * 60,
MaxEntrySize: 500,
Verbose: true,
HardMaxCacheSize: 300,
OnRemove: nil,
OnRemoveWithReason: nil,
}
cache, err := bigcache.NewBigCache(cfg)
if err != nil {
panic(err)
}
err = cache.Set("name", []byte("sakti dwi cahyono"))
if err != nil {
panic(err)
}
entry, err := cache.Get("name")
fmt.Println("error get = ", err)
fmt.Println(string(entry))
i := 1
go func() {
for j := 0; j < 1000000000000000; j++ {
cache.Set(fmt.Sprintf("%d", j), []byte("randomstring"))
if j%100000 == 0 {
debug.FreeOSMemory()
fmt.Println(j)
}
}
}()
for {
reader := bufio.NewReader(os.Stdin)
reader.ReadString('\n')
cache.Set(fmt.Sprintf("%d", i), []byte("randomstring"))
fmt.Println("capacity = ", humanize.Bytes(uint64(cache.Capacity())))
i += 1
}
/*
_, err = cache.Get("name2")
fmt.Println(err)
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment