cache

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

go-cache

Benchmark:

JLMP250:go-cache amitt$ go test -timeout 30m -bench=. -benchmem -memprofile memprofile.out -cpuprofile profile.out -benchtime=20s -count=5 goos: darwin goarch: arm64 pkg: github.com/amitiwary999/go-cache BenchmarkBigCache-10 1000000000 2.102 ns/op 0 B/op 0 allocs/op BenchmarkBigCache-10 1000000000 2.139 ns/op 0 B/op 0 allocs/op BenchmarkBigCache-10 1000000000 2.172 ns/op 0 B/op 0 allocs/op

When I tried with map size 400000 there is almost no allocation. But when I increase the size and save the 800000 key on map the result was

BenchmarkBigCache-10 1 2409240291 ns/op 206634832 B/op 5508270 allocs/op BenchmarkBigCache-10 1 2371712709 ns/op 206603024 B/op 5508174 allocs/op BenchmarkBigCache-10 1 2471930375 ns/op 206604184 B/op 5508217 allocs/op

See the allocation. Suddenly there is lot of allocation and most happening in save where we use map to save the key offset.

Tracking GC pause with the map key type string go test -timeout 30m -bench=. -benchmem -memprofile memprofile.out -cpuprofile profile.out -benchtime=2s -count=3 With a map of strings, GC took: 8.35775ms\ngoos: darwin goarch: arm64 pkg: github.com/amitiwary999/go-cache BenchmarkBigCache-10 1 2513947625 ns/op 206583752 B/op 5507991 allocs/op BenchmarkBigCache-10 With a map of strings, GC took: 13.244958ms\n 1 2648101667 ns/op 206521816 B/op 5507817 allocs/op BenchmarkBigCache-10 With a map of strings, GC took: 12.969667ms\n 1 2680075792 ns/op 206567632 B/op 5508013 allocs/op PASS ok github.com/amitiwary999/go-cache 7.991s

Tracking GC pause with map key type int go test -timeout 30m -bench=. -benchmem -memprofile memprofile.out -cpuprofile profile.out -benchtime=2s -count=3 With a map of strings, GC took: 1.404083ms\ngoos: darwin goarch: arm64 pkg: github.com/amitiwary999/go-cache BenchmarkBigCache-10 1 2739409458 ns/op 168656952 B/op 5578545 allocs/op BenchmarkBigCache-10 With a map of strings, GC took: 1.817875ms\n 1 2623270083 ns/op 168584712 B/op 5578105 allocs/op BenchmarkBigCache-10 With a map of strings, GC took: 2.818375ms\n 1 2663439166 ns/op 168562432 B/op 5578132 allocs/op PASS

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBigCacheRing

func NewBigCacheRing(bufferSize int32) (*bigCacheRing, error)

func NewCacheRing

func NewCacheRing[T any](capacity int32) *cacheRing[T]

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[T any](cleanupInterval int16, done chan int) *Cache[T]

func NewCacheWithCapacity

func NewCacheWithCapacity[T any](capacity, cleanupInterval int16, done chan int) *Cache[T]

func (*Cache[T]) Add

func (c *Cache[T]) Add(key string, value T, expirationSecond int64) error

func (*Cache[T]) Delete

func (c *Cache[T]) Delete(key string)

func (*Cache[T]) Get

func (c *Cache[T]) Get(key string) (T, error)

func (*Cache[T]) Set

func (c *Cache[T]) Set(key string, value T, expirationSecond int64) error

func (*Cache[T]) StopCleanUp

func (c *Cache[T]) StopCleanUp()

type CacheItem

type CacheItem[T any] struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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