filebasedcache

package
v0.0.0-...-be99ba7 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	READ  Msg = "READ"
	WRITE     = "WRITE"
	EVICT     = "EVICT"
)

Variables

This section is empty.

Functions

func NewCache

func NewCache(dirpath string, ledgerFile *os.File) pokeapi.Cache

NewCache returns a filebasedcache that satisfies the interface of the pokeapi.Cache. When this is instantiated, under the hood, it will create a ledger which holds reference to a file path and a directory path.

Types

type Cache

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

func (*Cache) Add

func (c *Cache) Add(url string, data []byte)

Add will add the url and data response to the cache. Internally, it interacts with the ledger by first checking to see if there is room, and inserting if the cache has capacity. Otherwise, it checks the least recently updated (LRU) entry, and removes the lru file. At which point, the cache is fine to write to, and the url and data is persisted.

func (*Cache) Get

func (c *Cache) Get(url string) ([]byte, bool)

Get will look for the data and return the data that was stored by the given url. This pointer receiver will return boolean indicating if the data was found.

type Ledger

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

func NewLedger

func NewLedger(ledgerFile *os.File) *Ledger

func (*Ledger) Bytes

func (l *Ledger) Bytes() []byte

func (*Ledger) Entry

func (l *Ledger) Entry() LedgerEntry

Entry returns the next LedgerEntry in the ledgerFile function panics if encountering an error parsing the entry.

func (*Ledger) IsUniq

func (l *Ledger) IsUniq(filename string) bool

func (*Ledger) Log

func (l *Ledger) Log(entry LedgerEntry)

func (*Ledger) Parse

func (l *Ledger) Parse(data []byte) (LedgerEntry, error)

func (*Ledger) Read

func (l *Ledger) Read()

func (*Ledger) Restore

func (l *Ledger) Restore(c *Cache) error

Restore replays the history of the ledger returning the log entries

func (*Ledger) Scan

func (l *Ledger) Scan() bool

func (*Ledger) Text

func (l *Ledger) Text() string

type LedgerEntry

type LedgerEntry struct {
	Msg      Msg       `json:"msg"`
	Filename string    `json:"filename"`
	Url      string    `json:"url"`
	Time     time.Time `json:"time"`
}

type List

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

func NewList

func NewList(capacity int) *List

func (*List) Capacity

func (l *List) Capacity() int

func (*List) Empty

func (l *List) Empty() bool

func (*List) Entry

func (l *List) Entry() LedgerEntry

func (*List) Full

func (l *List) Full() bool

func (*List) Pop

func (l *List) Pop() (LedgerEntry, bool)

func (*List) Push

func (l *List) Push(entry LedgerEntry) bool

func (*List) Remove

func (l *List) Remove(entry LedgerEntry)

func (*List) Reset

func (l *List) Reset() bool

func (*List) Scan

func (l *List) Scan() bool

func (*List) Setup

func (l *List) Setup(entries []LedgerEntry)

func (*List) Size

func (l *List) Size() int

type Msg

type Msg string

type Node

type Node struct {
	Value LedgerEntry
	Next  *Node
}

Jump to

Keyboard shortcuts

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