cache

package
v0.0.0-...-03f3354 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2015 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cache is implements the caching algorithm. It defines the CacheManager interface. Every CacheZone has its own cache manager. This makes it possible for different caching algorithms to be used in the same time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheManager

type CacheManager interface {

	// Init is called only once after creating the CacheManager object
	Init()

	// Has returns wheather this object is in the cache or not
	Has(types.ObjectIndex) bool

	// ObjectIndexStored is called to signal that this ObjectIndex has been stored
	ObjectIndexStored(types.ObjectIndex) bool

	// AddObjectIndex adds this ObjectIndex to the cache
	AddObjectIndex(types.ObjectIndex) error

	// UsedObjectIndex is called every time this part of a file has been used
	// to satisfy a client request
	UsedObjectIndex(types.ObjectIndex)

	// ConsumedSize returns the full size of all files currently in the cache
	ConsumedSize() config.BytesSize

	// ReplaceRemoveChannel makes this cache communicate its desire to remove objects
	// on this channel
	ReplaceRemoveChannel(chan<- types.ObjectIndex)

	// Stats returns statistics for this cache manager
	Stats() *CacheStats
}

CacheManager interface defines how a cache should behave

func NewCacheManager

func NewCacheManager(ct string, cz *config.CacheZoneSection) (CacheManager, error)

NewCacheManager creates and returns a particular type of cache manager.

type CacheStats

type CacheStats struct {
	ID       string
	Hits     uint64
	Requests uint64
	Size     config.BytesSize
	Objects  uint64
}

func (*CacheStats) CachHitPrc

func (c *CacheStats) CachHitPrc() string

type LRUCache

type LRUCache struct {
	CacheZone *config.CacheZoneSection
	// contains filtered or unexported fields
}

Implements segmented LRU Cache. It has cacheTiers segments.

func (*LRUCache) AddObjectIndex

func (l *LRUCache) AddObjectIndex(oi ObjectIndex) error

Implements part of CacheManager interface

func (*LRUCache) ConsumedSize

func (l *LRUCache) ConsumedSize() config.BytesSize

Implements part of CacheManager interface

func (*LRUCache) Has

func (l *LRUCache) Has(oi ObjectIndex) bool

Implements part of CacheManager interface

func (*LRUCache) Init

func (l *LRUCache) Init()

Implements part of CacheManager interface

func (*LRUCache) ObjectIndexStored

func (l *LRUCache) ObjectIndexStored(oi ObjectIndex) bool

Implements part of CacheManager interface

func (*LRUCache) ReplaceRemoveChannel

func (l *LRUCache) ReplaceRemoveChannel(ch chan<- ObjectIndex)

func (*LRUCache) Stats

func (l *LRUCache) Stats() *CacheStats

Implements part of CacheManager interface

func (*LRUCache) UsedObjectIndex

func (l *LRUCache) UsedObjectIndex(oi ObjectIndex)

Implements part of CacheManager interface. It will reorder the linke lists so that this object index will be get promoted in rank.

type LRUElement

type LRUElement struct {
	ListElem *list.Element
	ListTier int
}

Jump to

Keyboard shortcuts

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