piececache

package
v1.8.10 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	NumCached      metrics.Meter
	NumTotal       metrics.Meter
	NumLoad        metrics.Meter
	NumLoadedBytes metrics.Meter
	// contains filtered or unexported fields
}

Cache is a LRU piece cache of certain size. Items in the cache are expired after the defined TTL.

func New

func New(maxSize int64, ttl time.Duration, parallelReads uint) *Cache

New returns new Cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear the cache. Drops all items in cache.

func (*Cache) Close added in v0.3.0

func (c *Cache) Close()

Close the cache and release all resources.

func (*Cache) Get

func (c *Cache) Get(key string, loader Loader) ([]byte, error)

Get item with the key from cache. If item is not in cache, load by calling `loader` func and put into the cache.

func (*Cache) Len added in v0.3.0

func (c *Cache) Len() int

Len returns the number of items in the cache. Items may be in different sizes.

func (*Cache) LoadsActive added in v0.5.5

func (c *Cache) LoadsActive() int

LoadsActive returns the number of active Loader calls.

func (*Cache) LoadsWaiting added in v0.5.2

func (c *Cache) LoadsWaiting() int

LoadsWaiting returns the number of waiting Loader calls.

func (*Cache) Size added in v0.3.0

func (c *Cache) Size() int64

Size returns the total size of the items in the cache.

func (*Cache) Utilization added in v0.3.0

func (c *Cache) Utilization() int

Utilization is a number between 0 and 100 that returns the hit-ratio of the cache.

type Loader

type Loader func() ([]byte, error)

Loader is a function that loads data from a piece.

Jump to

Keyboard shortcuts

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