disklru

package module
v0.0.0-...-3c11522 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

Disk LRU

This library provides a sqlite based LRU.

Documentation

Index

Constants

View Source
const (
	NS = 1000000000
)

Variables

View Source
var (
	KeyNotFoundError = errors.New("Key not found error")
)

Functions

This section is empty.

Types

type CacheItem

type CacheItem struct {
	Key   string
	Value interface{}
}

type Clock

type Clock interface {
	// Returns the time in nanosec since the epoch
	// e.g. time.Now().UnixNano()
	Now() int64
}

type Counter

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

func (*Counter) Get

func (self *Counter) Get() int

func (*Counter) Inc

func (self *Counter) Inc()

type DiskLRU

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

func NewDiskLRU

func NewDiskLRU(
	ctx context.Context, opts Options) (*DiskLRU, error)

func (*DiskLRU) Close

func (self *DiskLRU) Close() error

func (*DiskLRU) Debug

func (self *DiskLRU) Debug(msg string, args ...interface{})

func (*DiskLRU) Delete

func (self *DiskLRU) Delete(key string) bool

func (*DiskLRU) Dump

func (self *DiskLRU) Dump()

func (*DiskLRU) Get

func (self *DiskLRU) Get(key string) (interface{}, error)

func (*DiskLRU) HouseKeepOnce

func (self *DiskLRU) HouseKeepOnce()

func (*DiskLRU) Items

func (self *DiskLRU) Items() (res []CacheItem)

func (*DiskLRU) Peek

func (self *DiskLRU) Peek(key string) (interface{}, error)

func (*DiskLRU) Purge

func (self *DiskLRU) Purge() error

func (*DiskLRU) Set

func (self *DiskLRU) Set(key string, value interface{}) error

func (*DiskLRU) SetEncoder

func (self *DiskLRU) SetEncoder(encoder Encoder)

func (*DiskLRU) Stats

func (self *DiskLRU) Stats() Stats

type Encoder

type Encoder interface {
	Encode(obj interface{}) ([]byte, error)
	Decode(in []byte) (interface{}, error)
}

type JsonEncoder

type JsonEncoder struct{}

func (JsonEncoder) Decode

func (self JsonEncoder) Decode(in []byte) (interface{}, error)

func (JsonEncoder) Encode

func (self JsonEncoder) Encode(obj interface{}) ([]byte, error)

type Options

type Options struct {
	// Path to the sqlite cache file.
	Filename string

	// Clear the file on start
	ClearOnStart bool

	// The maximum number of items to keep in cache
	MaxSize int

	// How long to keep items in cache
	MaxExpirySec int

	// Should expiry time be updated on access?
	UpdateExpiryOnAccess bool

	// How often to run the housekeeping thread, negative number
	// disables automatic housekeeping.
	HouseKeepPeriodSec int64

	// The clock is used to control time in tests etc.
	Clock Clock

	// Set for explicit debugging.
	DEBUG bool
}

Control the behavious of the cache

func (*Options) UpdateDefaults

func (self *Options) UpdateDefaults()

Set some reasonable defaults.

type RealClock

type RealClock struct{}

func (*RealClock) Now

func (self *RealClock) Now() int64

type Stats

type Stats struct {
	Length, Size, Capacity, Evictions int64
	Hits, Misses                      int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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