cache

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package cache provides basic block cache types for the bgzf package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Free

func Free(n int, c Cache) bool

Free attempts to drop as many blocks from c as needed allow n successful Put calls on c. It returns a boolean indicating whether n slots were made available.

Types

type Cache

type Cache interface {
	bgzf.Cache

	// Len returns the number of elements held by
	// the cache.
	Len() int

	// Cap returns the maximum number of elements
	// that can be held by the cache.
	Cap() int

	// Resize changes the capacity of the cache to n,
	// dropping excess blocks if n is less than the
	// number of cached blocks.
	Resize(n int)

	// Drop evicts n elements from the cache according
	// to the cache eviction policy.
	Drop(n int)
}

Cache is an extension of bgzf.Cache that allows inspection and manipulation of the cache.

func NewFIFO

func NewFIFO(n int) Cache

NewFIFO returns a FIFO cache with n slots. If n is less than 1 a nil cache is returned.

func NewLRU

func NewLRU(n int) Cache

NewLRU returns an LRU cache with n slots. If n is less than 1 a nil cache is returned.

func NewRandom

func NewRandom(n int) Cache

NewRandom returns a random eviction cache with n slots. If n is less than 1 a nil cache is returned.

type FIFO

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

FIFO satisfies the Cache interface with first in first out eviction behavior where Unused Blocks are preferentially evicted.

func (*FIFO) Cap

func (c *FIFO) Cap() int

Cap returns the maximum number of elements that can be held by the cache.

func (*FIFO) Drop

func (c *FIFO) Drop(n int)

Drop evicts n elements from the cache according to the cache eviction policy.

func (*FIFO) Get

func (c *FIFO) Get(base int64) bgzf.Block

Get returns the Block in the Cache with the specified base or a nil Block if it does not exist.

func (*FIFO) Len

func (c *FIFO) Len() int

Len returns the number of elements held by the cache.

func (*FIFO) Peek

func (c *FIFO) Peek(base int64) (exist bool, next int64)

Peek returns a boolean indicating whether a Block exists in the Cache for the given base offset and the expected offset for the subsequent Block in the BGZF stream.

func (*FIFO) Put

func (c *FIFO) Put(b bgzf.Block) (evicted bgzf.Block, retained bool)

Put inserts a Block into the Cache, returning the Block that was evicted or nil if no eviction was necessary and the Block was retained. Unused Blocks are not retained but are returned if the Cache is full.

func (*FIFO) Resize

func (c *FIFO) Resize(n int)

Resize changes the capacity of the cache to n, dropping excess blocks if n is less than the number of cached blocks.

type LRU

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

LRU satisfies the Cache interface with least recently used eviction behavior where Unused Blocks are preferentially evicted.

func (*LRU) Cap

func (c *LRU) Cap() int

Cap returns the maximum number of elements that can be held by the cache.

func (*LRU) Drop

func (c *LRU) Drop(n int)

Drop evicts n elements from the cache according to the cache eviction policy.

func (*LRU) Get

func (c *LRU) Get(base int64) bgzf.Block

Get returns the Block in the Cache with the specified base or a nil Block if it does not exist.

func (*LRU) Len

func (c *LRU) Len() int

Len returns the number of elements held by the cache.

func (*LRU) Peek

func (c *LRU) Peek(base int64) (exist bool, next int64)

Peek returns a boolean indicating whether a Block exists in the Cache for the given base offset and the expected offset for the subsequent Block in the BGZF stream.

func (*LRU) Put

func (c *LRU) Put(b bgzf.Block) (evicted bgzf.Block, retained bool)

Put inserts a Block into the Cache, returning the Block that was evicted or nil if no eviction was necessary and the Block was retained. Unused Blocks are not retained but are returned if the Cache is full.

func (*LRU) Resize

func (c *LRU) Resize(n int)

Resize changes the capacity of the cache to n, dropping excess blocks if n is less than the number of cached blocks.

type Random

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

Random satisfies the Cache interface with random eviction behavior where Unused Blocks are preferentially evicted.

func (*Random) Cap

func (c *Random) Cap() int

Cap returns the maximum number of elements that can be held by the cache.

func (*Random) Drop

func (c *Random) Drop(n int)

Drop evicts n elements from the cache according to the cache eviction policy.

func (*Random) Get

func (c *Random) Get(base int64) bgzf.Block

Get returns the Block in the Cache with the specified base or a nil Block if it does not exist.

func (*Random) Len

func (c *Random) Len() int

Len returns the number of elements held by the cache.

func (*Random) Peek

func (c *Random) Peek(base int64) (exist bool, next int64)

Peek returns a boolean indicating whether a Block exists in the Cache for the given base offset and the expected offset for the subsequent Block in the BGZF stream.

func (*Random) Put

func (c *Random) Put(b bgzf.Block) (evicted bgzf.Block, retained bool)

Put inserts a Block into the Cache, returning the Block that was evicted or nil if no eviction was necessary and the Block was retained. Unused Blocks are not retained but are returned if the Cache is full.

func (*Random) Resize

func (c *Random) Resize(n int)

Resize changes the capacity of the cache to n, dropping excess blocks if n is less than the number of cached blocks.

type Stats

type Stats struct {
	Gets      int // number of Get operations
	Misses    int // number of cache misses
	Puts      int // number of Put operations
	Retains   int // number of times a Put has resulted in Block retention
	Evictions int // number of times a Put has resulted in a Block eviction
}

Stats represents statistics of a bgzf.Cache.

type StatsRecorder

type StatsRecorder struct {
	bgzf.Cache
	// contains filtered or unexported fields
}

StatsRecorder allows a bgzf.Cache to capture cache statistics.

func (*StatsRecorder) Get

func (s *StatsRecorder) Get(base int64) bgzf.Block

Get returns the Block in the underlying Cache with the specified base or a nil Block if it does not exist. It updates the gets and misses statistics.

func (*StatsRecorder) Put

func (s *StatsRecorder) Put(b bgzf.Block) (evicted bgzf.Block, retained bool)

Put inserts a Block into the underlying Cache, returning the Block and eviction status according to the underlying cache behavior. It updates the puts, retains and evictions statistics.

func (*StatsRecorder) Reset

func (s *StatsRecorder) Reset()

Reset zeros the statistics kept by the StatsRecorder.

func (*StatsRecorder) Stats

func (s *StatsRecorder) Stats() Stats

Stats returns the current statistics for the cache.

Jump to

Keyboard shortcuts

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