Created
August 30, 2018 10:28
-
-
Save sakti/b91aa2119ce10ad1faa307605f080a49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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