cache

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

package cache

package cache is bytes/interface cache manager.

Usage:

import "github.com/hetianyi/gox/cache"
// apply cache
bc := cache.ApplyBytes(bufferSize, false)
// recache
defer cache.ReCacheBytes(bc)
// use cache...
性能测试对比

测试用例参考:https://github.com/hetianyi/golib-test/blob/master/src/http_upload_server.go

使用cache 不使用cache
代码分支 master old_http
NumGC
Mallocs
TotalAlloc 500,928,176 3,686,271,360
PauseTotalNs 25,549,814 141,964,319
PauseNs 3,003,165 14,152,667

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyResource

func ApplyResource(p reflect.Type, fallback func() interface{}) interface{}

ApplyResource applies specified type of resource which cached before.

func ReCacheBytes

func ReCacheBytes(bc ByteCapsule)

ReCacheBytes caches bytes ByteCapsule

func ReCacheResource

func ReCacheResource(res interface{})

ReCacheResource caches bytes ByteCapsule

func SetCacheBytesListSize

func SetCacheBytesListSize(size int)

SetCacheBytesListSize sets max size of each cache list.

func SetCacheResourceListSize

func SetCacheResourceListSize(size int)

SetCacheResourceListSize sets max size of each cache list.

Types

type ByteCapsule

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

ByteCapsule is small bytes container

func ApplyBytes

func ApplyBytes(size int, dynamic bool) ByteCapsule

ApplyBytes applies specified size of bytes array. dynamic bytes apply will not be cached

func (*ByteCapsule) Bytes

func (bc *ByteCapsule) Bytes() []byte

Bytes returns bytes array of ByteCapsule

Jump to

Keyboard shortcuts

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