# cache **Repository Path**: go-needle/cache ## Basic Information - **Project Name**: cache - **Description**: a simple cache framework for golang - **Primary Language**: Go - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-22 - **Last Updated**: 2024-11-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
# 🪡cache a simple cache framework for golang golang
## introduction This is a cache framework implemented by Golang. This framework implements the FIFO and LRU algorithms for managing cache and is thread safe. The algorithm needs to be selected based on the actual situation, and using FIFO in an environment with more reads and less writes will result in higher performance. ## installing Select the version to install `go get github.com/go-needle/cache@version` If you have already get , you may need to update to the latest version `go get -u github.com/go-needle/cache` ## quickly start ```golang package main import ( "fmt" "github.com/go-needle/cache" "math/rand" "strconv" "time" ) func main() { c := cache.NewLRU(1024, time.Duration(10)*time.Second) //c := cache.NewFIFO(1<<32, time.Duration(10)*time.Second) for i := 0; i < 1000; i++ { num := i go func() { time.Sleep(time.Duration(rand.Intn(10)) * time.Second) c.Add("key"+strconv.Itoa(num), []byte(strconv.Itoa(num))) }() } for i := 0; i < 1000; i++ { num := i go func() { time.Sleep(time.Duration(rand.Intn(20)) * time.Second) v, ok := c.Get("key" + strconv.Itoa(num)) fmt.Println(v.String(), ok) }() } time.Sleep(time.Duration(20) * time.Second) } ```