cache is an in memory cache library to handle caches in the form of key value or FIFO style queue with expiration support.
The main advantage is that we can have one timer to watch multiple cache objects this increases efficiency compared
to patrickmn/go-cache when you need to have a large number of cache objects.
To install this package, use go get:
go get -u github.com/ponder2000/cachepackage main
import (
"fmt"
"time"
"github.com/ponder2000/cache"
)
func main() {
// suppose you want to create one janitor for 100 cache where the janitors will clean all 100 caches expired item after 3 seconds
numberOfCachePerJanitor := 100
janitorCleanupSchedule := time.Second * 3
janitorOption := cache.NewJanitorConfigOption(numberOfCachePerJanitor, janitorCleanupSchedule)
janitorPool := cache.NewJanitorPool(janitorOption)
// now keep creating cache object as much as you want and register it to the janitor pool
for i := 0; i<1000; i++ {
cache := cache.NewListCacher(time.Second * 1)
janitorPool.RegisterCache(cache)
}
// note : in the above case janitor pool will have 10 janitor looking after 100 caches each
}For full package documentation, visit pkg.go.dev.
This project is licensed under the MIT License.
Inspired from patrickmn/go-cache
- Jay Saha
- Twitter: @chotathanos
Feel free to reach out if you have any questions or feedback!