lru

package
v0.0.0-...-37fe1c2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: BSD-3-Clause Imports: 14 Imported by: 32

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanOutOfSyncWithDelay

func CleanOutOfSyncWithDelay(mctx libkb.MetaContext, d *DiskLRU, cacheDir string, delay time.Duration)

CleanOutOfSyncWithDelay runs the LRU clean function after the `delay` duration. If the service crashes it's possible that temporarily files get stranded on disk before they can get recorded in the LRU. Callers can run this in the background to prevent leaking space. We delay to keep off the critical path to start up.

Types

type Cache

type Cache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewLRU

func NewLRU(ctx libkb.LRUContext, sz int, version int, exampleObj interface{}) *Cache

func (*Cache) ClearMemory

func (c *Cache) ClearMemory()

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, lctx libkb.LRUContext, k libkb.LRUKeyer) (interface{}, error)

func (*Cache) OnDbNuke

func (c *Cache) OnDbNuke(mctx libkb.MetaContext) error

func (*Cache) OnLogout

func (c *Cache) OnLogout(mctx libkb.MetaContext) error

func (*Cache) Put

func (c *Cache) Put(ctx context.Context, lctx libkb.LRUContext, k libkb.LRUKeyer, v interface{}) error

type DiskLRU

type DiskLRU struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DiskLRU maintains a cache of files on the disk in a LRU manner.

func NewDiskLRU

func NewDiskLRU(name string, version, maxSize int) *DiskLRU

func (*DiskLRU) CleanOutOfSync

func (d *DiskLRU) CleanOutOfSync(mctx libkb.MetaContext, cacheDir string) error

func (*DiskLRU) ClearMemory

func (d *DiskLRU) ClearMemory(ctx context.Context, lctx libkb.LRUContext)

func (*DiskLRU) Flush

func (d *DiskLRU) Flush(ctx context.Context, lctx libkb.LRUContext) error

func (*DiskLRU) Get

func (d *DiskLRU) Get(ctx context.Context, lctx libkb.LRUContext, key string) (found bool, res DiskLRUEntry, err error)

func (*DiskLRU) MaxSize

func (d *DiskLRU) MaxSize() int

func (*DiskLRU) Put

func (d *DiskLRU) Put(ctx context.Context, lctx libkb.LRUContext, key string, value interface{}) (evicted *DiskLRUEntry, err error)

func (*DiskLRU) Remove

func (d *DiskLRU) Remove(ctx context.Context, lctx libkb.LRUContext, key string) (err error)

func (*DiskLRU) Size

func (d *DiskLRU) Size(ctx context.Context, lctx libkb.LRUContext) (int, error)

type DiskLRUEntry

type DiskLRUEntry struct {
	Key          string
	Value        interface{}
	Ctime        time.Time
	LastAccessed time.Time
}

type Pathable

type Pathable struct {
	Path string
}

Jump to

Keyboard shortcuts

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