cache

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: Apache-2.0 Imports: 18 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 Config

type Config struct {
	rs.BaseField `yaml:"-"`

	// EnableCache activates rendered data caching
	//
	// * for renderers reading data directly from local disk (e.g. file):
	//     will cache content in memory with size limit applied
	// * for renderers doing remote fetch (e.g. http, git, af):
	//     will cache data on local disk first (cache size limiting is not effective at this time)
	// 	   then cache data in memory with size limit applied
	//
	// Defaults to `false`
	EnableCache bool `yaml:"enable_cache"`

	// CacheItemSizeLimit is the maximum size limit an item can be cached in memory
	//
	// Format: <number><unit>
	// 	where unit can be one of: [ , B, KB, MB, GB, TB, PB]
	//
	// Defaults to `0` (no size limit for single item)
	CacheItemSizeLimit utils.Size `yaml:"cache_item_size_limit"`

	// CacheSizeLimit limits maximum in memory size of cache of the renderer
	//
	// Format: <number><unit>
	// 	where unit can be one of: [ , B, KB, MB, GB, TB, PB]
	//
	// Defaults to `0` (no size limit)
	CacheSizeLimit utils.Size `yaml:"cache_size_limit"`

	// CacheMaxAge limits maximum data caching time
	//
	// if caching is enabled and this option is set to 0:
	//  in memory cache will never expire during runtime
	// 	file cache for remote content will expire immediately (probably that's not what you want)
	//
	// Defaults to `0`
	CacheMaxAge time.Duration `yaml:"cache_max_age"`
}

Config is the config for rendered data caching

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(cacheDir string, 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