cache

package
v0.0.0-...-f404d8c Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2019 License: MIT Imports: 12 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 interface {
	KeyPresent(key string) bool
	GetValue(key string) (Entry, error)
	SetValue(key string, value Entry) error
}

Cache is the thing the server knows how to ask about the existance of a particular entry. Various implementations can be built that correspond to this interface

func NewCache

func NewCache(cacheType string, size int) (Cache, error)

NewCache is a factory for building a cache implementation of the requested strategy

type Calecar

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

Calecar balances a frequency and recency distribution https://www.usenix.org/system/files/conference/hotstorage18/hotstorage18-paper-vietri.pdf

func (*Calecar) GetValue

func (c *Calecar) GetValue(k string) (Entry, error)

GetValue will return the entry if present in the lookup

func (*Calecar) KeyPresent

func (c *Calecar) KeyPresent(k string) bool

KeyPresent is true if the key is in the cache right now

func (*Calecar) SetValue

func (c *Calecar) SetValue(k string, v Entry) error

SetValue inserts a new cache entry, evicting one if necessary

type Entry

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

Entry is the thing stored in a cache, both the actual value of the result and the measured cost to recompute it

type FiFo

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

FiFo is a First-in-fist-out cache implementation. When full, it will always decide to evict the oldest key added.

func (*FiFo) GetValue

func (ff *FiFo) GetValue(k string) (Entry, error)

GetValue will return the entry if present in the lookup

func (*FiFo) KeyPresent

func (ff *FiFo) KeyPresent(k string) bool

KeyPresent is true if the key is in the cache right now

func (*FiFo) SetValue

func (ff *FiFo) SetValue(k string, v Entry) error

SetValue inserts a new cache entry, evicting one if necessary

type Lcr

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

Lcr is a cache implementation adapting to cost of recomputation. When full, it will always decide to evict the key with the lowest cost to recompute.

func (*Lcr) GetValue

func (l *Lcr) GetValue(k string) (Entry, error)

GetValue will return the entry if present in the lookup

func (*Lcr) KeyPresent

func (l *Lcr) KeyPresent(k string) bool

KeyPresent is true if the key is in the cache right now

func (*Lcr) SetValue

func (l *Lcr) SetValue(k string, v Entry) error

SetValue inserts a new cache entry, evicting one if necessary

type Lecar

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

Lecar balances a frequency and recency distribution https://www.usenix.org/system/files/conference/hotstorage18/hotstorage18-paper-vietri.pdf

func (*Lecar) GetValue

func (l *Lecar) GetValue(k string) (Entry, error)

GetValue will return the entry if present in the lookup

func (*Lecar) KeyPresent

func (l *Lecar) KeyPresent(k string) bool

KeyPresent is true if the key is in the cache right now

func (*Lecar) SetValue

func (l *Lecar) SetValue(k string, v Entry) error

SetValue inserts a new cache entry, evicting one if necessary

type Lfu

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

Lfu is a cache implementation adapting to access frequency. When full, it will always decide to evict the key touched the least number of times.

func (*Lfu) GetValue

func (l *Lfu) GetValue(k string) (Entry, error)

GetValue will return the entry if present in the lookup

func (*Lfu) KeyPresent

func (l *Lfu) KeyPresent(k string) bool

KeyPresent is true if the key is in the cache right now

func (*Lfu) SetValue

func (l *Lfu) SetValue(k string, v Entry) error

SetValue inserts a new cache entry, evicting one if necessary

type Lru

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

Lru is a cache implementation adapting to access time. When full, it will always decide to evict the key touched the longest ago.

func (*Lru) GetValue

func (l *Lru) GetValue(k string) (Entry, error)

GetValue will return the entry if present in the lookup

func (*Lru) KeyPresent

func (l *Lru) KeyPresent(k string) bool

KeyPresent is true if the key is in the cache right now

func (*Lru) SetValue

func (l *Lru) SetValue(k string, v Entry) error

SetValue inserts a new cache entry, evicting one if necessary

type NoOp

type NoOp struct{}

NoOp is a dummy implementation. No keys are ever present, so it never has to replace anything. Naive baseline.

func (*NoOp) GetValue

func (cno *NoOp) GetValue(k string) (Entry, error)

GetValue will always return an error for the no-op cache

func (*NoOp) KeyPresent

func (cno *NoOp) KeyPresent(k string) bool

KeyPresent will always be false for the no-op cache

func (*NoOp) SetValue

func (cno *NoOp) SetValue(k string, v Entry) error

SetValue does nothing in the no-op cache

type Server

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

Server is the type that listens for fetch requests and returns them from the data file

func NewServer

func NewServer(conf *ServerConf) *Server

NewServer is a constructor for building a new server with config onboard

func (*Server) Listen

func (s *Server) Listen()

Listen is how you kick off a serve loop to wait for incoing connections

type ServerConf

type ServerConf struct {
	LogFile   *string
	DataFile  *string
	CacheType *string
	CacheSize int
	Verbose   bool
}

ServerConf holds the cmd flags and other config params for parameterizing the cache server

Jump to

Keyboard shortcuts

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