Sipmle cache provider by unified interface
go get -u github.com/0x75960/cch-go
- define driver satisfy cch.CacheDriver
// CacheDriver
type CacheDriver interface {
HasItem(key interface{}) bool
Add(item interface{})
Remove(key interface{})
Load()
Dump()
}
- initialze cch.Cache with cch.NewCache(driver CacheDriver)
/*
NOTE: `driver.Load` is called in NewCache
and set callback that call `driver.Dump` when process has interrupted
*/
cache := cch.NewCache()
- and set Dump to
defer
if you needed.
defer cache.Dump() // Optional
- use
Add
/Remove
/HasItem
in your process
/* for example */
if cache.HasItem(item) {
// if already seen
continue
}
// do something
cache.Add(item)