cache

package module
v0.0.0-...-4eb8726 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2023 License: MIT Imports: 3 Imported by: 0

README

cache

Go Reference Go Report Card License

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.

Installation

To install this package, use go get:

go get -u github.com/ponder2000/cache

Usage

package 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
	
}

Flow

Documentation

For full package documentation, visit pkg.go.dev.

License

This project is licensed under the MIT License.

Acknowledgments

Inspired from patrickmn/go-cache

Contact

Feel free to reach out if you have any questions or feedback!

Documentation

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL