cch

package module
v0.0.0-...-ad8140e Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2017 License: MIT Imports: 2 Imported by: 0

README

cch-go

Sipmle cache provider by unified interface

usage

installation
go get -u github.com/0x75960/cch-go
in code
  1. define driver satisfy cch.CacheDriver
// CacheDriver
type CacheDriver interface {
	HasItem(key interface{}) bool
	Add(item interface{})
	Remove(key interface{})
	Load()
	Dump()
}
  1. 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()
  1. and set Dump to defer if you needed.
defer cache.Dump() // Optional
  1. use Add / Remove / HasItem in your process
/* for example  */

if cache.HasItem(item) {
	// if already seen
	continue
}

// do something

cache.Add(item)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provider

func NewCache

func NewCache(driver CacheDriver) Cache

NewCache with specified Driver

func (Cache) Add

func (c Cache) Add(item interface{})

Add item to cache

func (Cache) Dump

func (c Cache) Dump()

Dump cache if needed

func (Cache) HasItem

func (c Cache) HasItem(key interface{}) bool

HasItem in cache

func (Cache) Remove

func (c Cache) Remove(key interface{})

Remove item has key from cache

type CacheDriver

type CacheDriver interface {
	HasItem(key interface{}) bool
	Add(item interface{})
	Remove(key interface{})
	Load()
	Dump()
}

CacheDriver interface

Jump to

Keyboard shortcuts

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