cachemachine

package module
v0.0.0-...-a875989 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiskCacheSyncInterval = time.Second * 30
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheMachine

type CacheMachine struct {
	MaxItemSizeInBytes   int
	CacheSyncTable       map[string]CacheSyncTable
	RamCache             *freecache.Cache
	RamCacheSizeInBytes  int
	DiskCache            *stash.Cache
	DiskCacheSizeInBytes int64
	DiskCachePath        string
	DiskCacheSyncTicker  *time.Ticker
	DiskCacheSyncQuit    chan int
	Logger               Logger
}

func NewCacheMachine

func NewCacheMachine(maxRamCacheSizeInBytes int, maxItemSizeInBytes int) (cm *CacheMachine, err error)

func (*CacheMachine) ClearDiskCache

func (c *CacheMachine) ClearDiskCache()

ClearDiskCache clears the cache.

func (*CacheMachine) ClearRamCache

func (c *CacheMachine) ClearRamCache()

ClearRamCache clears the cache.

func (*CacheMachine) Delete

func (c *CacheMachine) Delete(key string) bool

Delete deletes the value for the given key. If the key exists, Delete returns true. If the key does not exist, Delete returns false.

func (*CacheMachine) DisableDiskCache

func (c *CacheMachine) DisableDiskCache()

func (*CacheMachine) EnableDiskCache

func (c *CacheMachine) EnableDiskCache(maxDiskCacheSizeInBytes int64, cachePath string) (err error)

func (*CacheMachine) EnableS3Cache

func (c *CacheMachine) EnableS3Cache(maxItemSizeInBytes int, s3Bucket string) (err error)

func (*CacheMachine) Get

func (c *CacheMachine) Get(key string) (value []byte, ok bool)

Get returns the value for the given key. If the key exists, Get returns the value and true. If the key does not exist, Get returns nil and false.

func (*CacheMachine) RamCacheSize

func (c *CacheMachine) RamCacheSize() int

RamCacheSize returns the size of the cache in bytes.

func (*CacheMachine) Set

func (c *CacheMachine) Set(key string, val []byte) error

Set sets the value for the given key. If the key is larger than 65535 or value is larger than 1/1024 of the cache size, the entry will not be written to the cache.

func (*CacheMachine) SetLogger

func (c *CacheMachine) SetLogger(logger *Logger)

func (*CacheMachine) SyncRamCacheToDiskCache

func (c *CacheMachine) SyncRamCacheToDiskCache()

type CacheSyncTable

type CacheSyncTable struct {
	DiskSynced bool
	S3Sync     bool
}

type DefaultLogger

type DefaultLogger struct{}

func (DefaultLogger) Log

func (l DefaultLogger) Log(v ...interface{})

func (DefaultLogger) Logf

func (l DefaultLogger) Logf(format string, v ...interface{})

type Logger

type Logger interface {
	Log(v ...interface{})
	Logf(format string, v ...interface{})
}

Logger is the minimum interface that a logger must implement. It is used to log messages. The default logger is a no-op. The idea here is to decouple the logger from the library, so that the library can be used in contexts.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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