cache

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Build

func (builder *Builder) Build(loader Loader) *LocalCache

func (*Builder) ExpireAfterAccess

func (builder *Builder) ExpireAfterAccess(duration time.Duration) *Builder

func (*Builder) ExpireAfterWrite

func (builder *Builder) ExpireAfterWrite(duration time.Duration) *Builder

type Loader

type Loader interface {
	Load(key interface{}) (interface{}, error)
}

type LocalCache

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

1. 空间换时间。 通过冗余的两个数据结构(read、dirty),减少加锁对性能的影响。 2. 使用只读数据(read),避免读写冲突。 3. 动态调整,miss次数多了之后,将dirty数据提升为read。 4. double-checking。 5. 延迟删除。 删除一个键值只是打标记,只有在提升dirty的时候才清理删除的数据。 6. 优先从read读取、更新、删除,因为对read的读取不需要锁。

func (*LocalCache) Delete

func (cache *LocalCache) Delete(key interface{})

func (*LocalCache) Get

func (cache *LocalCache) Get(key interface{}) (interface{}, error)

func (*LocalCache) GetIfPresent

func (cache *LocalCache) GetIfPresent(key interface{}) interface{}

func (*LocalCache) Put

func (cache *LocalCache) Put(key, value interface{})

func (*LocalCache) Range

func (cache *LocalCache) Range(f func(key, value interface{}) bool)

type Mutex

type Mutex struct {
	sync.Mutex
}

实现一个带有 tryLock 功能的锁

func (*Mutex) TryLock

func (mu *Mutex) TryLock() bool

Jump to

Keyboard shortcuts

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