cache

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: LGPL-3.0 Imports: 6 Imported by: 1

README

cache Go Report CardGo Reference

different cache algorithms implementation in golang

go get git.sr.ht/~xn/cache
// example: LRU

lru := cache.NewLRU(1000)
lru.Set(1, 10)

If you need only specific cache algorithm, you can import it without additional dependencies:

go get git.sr.ht/~xn/cache/lfu
lfuCache := lfu.New(1000)
lfuCache.Set(1, 10)

status

implemented
tests
total:						(statements)	96.0%
benchmarks
goos: linux
goarch: amd64
pkg: git.sr.ht/~xn/cache/lfu
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkSet-8      	5137729	         293.8 ns/op	     47 B/op	      2 allocs/op
BenchmarkSetX2-8    	  36928	        120980 ns/op	     51 B/op	      3 allocs/op
BenchmarkGet-8      	8728536	         152.3 ns/op	      0 B/op	      0 allocs/op
BenchmarkHas-8         17306770          89.02 ns/op	      0 B/op	      0 allocs/op
BenchmarkRemove-8   	9493314	         233.2 ns/op	      0 B/op	      0 allocs/op
BenchmarkPurge-8    	  14232	        175344 ns/op	 909389 B/op	      3 allocs/op
goos: linux
goarch: amd64
pkg: git.sr.ht/~xn/cache/lru
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkSet-8      	 4158920	       297.3 ns/op	      47 B/op	       2 allocs/op
BenchmarkSetX2-8    	   38054	      123251 ns/op	      50 B/op	       3 allocs/op
BenchmarkGet-8      	 6358285	       223.5 ns/op	       0 B/op	       0 allocs/op
BenchmarkHas-8      	16789678	       85.98 ns/op	       0 B/op	       0 allocs/op
BenchmarkRemove-8   	 9418458	       228.6 ns/op	       0 B/op	       0 allocs/op
BenchmarkPurge-8    	   14974	      234563 ns/op	  909389 B/op	       3 allocs/op
goos: linux
goarch: amd64
pkg: git.sr.ht/~xn/cache/tlru
cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
BenchmarkSet-8      	3922689	         316.2 ns/op	     47 B/op	      2 allocs/op
BenchmarkSetX2-8    	  38558	        124703 ns/op	     50 B/op	      3 allocs/op
BenchmarkGet-8      	5020369	         232.1 ns/op	      0 B/op	      0 allocs/op
BenchmarkHas-8         14243359          95.20 ns/op	      0 B/op	      0 allocs/op
BenchmarkRemove-8   	8639568	         143.2 ns/op	      0 B/op	      0 allocs/op
BenchmarkPurge-8    	  10000	        186508 ns/op	 458824 B/op	      3 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get an item from cache
	Get(key interface{}) interface{}
	// Set an item to cache
	Set(key interface{}, value interface{})
	// Has an item in cache
	Has(key interface{}) bool
	// Remove an item from cache
	Remove(key interface{})
	// Purge all items from cache
	Purge()
}

Cache interface, used by any cache implementation

func NewLFU

func NewLFU(size int) Cache

NewLFU creates new Least Frequently Used cache

func NewLRU

func NewLRU(size int) Cache

NewLRU creates new Least Recently Used cache

func NewMemcached added in v1.2.0

func NewMemcached(ttl int32, servers ...string) Cache

NewMemcached creates new Memcached client

func NewNull added in v1.1.0

func NewNull() Cache

NewNull creates an empty cache client, usable for testing

func NewTLRU

func NewTLRU(size int, ttl time.Duration) Cache

NewTLRU cerates new Time aware Least Recently Used cache

Directories

Path Synopsis
Package memcached is a wrapper of github.com/bradfitz/gomemcache with Cache interface
Package memcached is a wrapper of github.com/bradfitz/gomemcache with Cache interface

Jump to

Keyboard shortcuts

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