cache

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: Apache-2.0 Imports: 15 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 struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(maxItemBytes, maxBytes, maxAgeSeconds int64) *Cache

NewCache is a in memory cache

maxItemBytes < 0, no limit

> 0, only data within this limit can be cached
== 0, disable in memory caching

maxBytes < 0, no limit

> 0, limit total cached in memory data with this size
== 0, disable in memory caching

maxAgeSeconds < 0, always fetch data

> 0, data become invalid after this duration
== 0, defaults to 5

func (*Cache) Get

func (c *Cache) Get(obj IdentifiableObject, refresh LocalCacheRefreshFunc) ([]byte, error)

type IdentifiableObject

type IdentifiableObject interface {
	ScopeUniqueID() string
	Ext() string
}

type IdentifiableString

type IdentifiableString string

func (IdentifiableString) Ext added in v0.6.0

func (s IdentifiableString) Ext() string

Ext returns file extension

func (IdentifiableString) ScopeUniqueID

func (s IdentifiableString) ScopeUniqueID() string

type LocalCacheRefreshFunc

type LocalCacheRefreshFunc func(obj IdentifiableObject) ([]byte, error)

type RemoteCacheRefreshFunc

type RemoteCacheRefreshFunc func(obj IdentifiableObject) (io.ReadCloser, error)

type TwoTierCache

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

func NewTwoTierCache

func NewTwoTierCache(
	cacheFS *fshelper.OSFS,
	itemMaxBytes, maxBytes, maxAgeSeconds int64,
) *TwoTierCache

NewTwoTierCache

itemMaxBytes < 0, no limit to item size

> 0, only items with size below can be cached
== 0, in memory caching disabled

maxBytes < 0, no limit to total cache size

> 0, limit cache size to maxBytes
== 0, in memory caching disabled

maxAgeSeconds <= 0, once cached in memory, always valid during runtime,

	   but will always fetch from remote if in memory cache lost
 > 0, limit both in memory and local file cache to this long.

func (*TwoTierCache) Get

func (c *TwoTierCache) Get(
	obj IdentifiableObject,
	now int64,
	allowExpired bool,
	refresh RemoteCacheRefreshFunc,
) ([]byte, bool, error)

Get cached content

now is the unix timestamp of the time being

func (*TwoTierCache) GetPath

func (c *TwoTierCache) GetPath(
	obj IdentifiableObject,
	now int64,
	allowExpired bool,
	refresh RemoteCacheRefreshFunc,
) (string, bool, error)

GetPath find local file path to cached data

now is the unix timestamp of the time being

Jump to

Keyboard shortcuts

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