Documentation ¶
Overview ¶
Package cache lazily loads information on demand and caches them. The data inside a cache has to implement the Cacheable interface which also contains methods for checking, if the information is outdated, and for discarding the cached instance. It is loaded by a user defined CacheableLoader function.
Index ¶
Constants ¶
const ( ErrSettingOptions = iota + 1 ErrIllegalCache ErrNoLoader ErrLoading ErrCheckOutdated ErrDiscard ErrDiscardedWhileLoading ErrTimeout ErrFileLoading ErrFileSize ErrFileChecking )
Errors of the Cache.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { // Load returns a Cacheable from memory or source. Load(id string, timeout time.Duration) (Cacheable, error) // Discard explicitly removes a Cacheable from Cache. Normally // done automatically. Discard(id string) error // Clear empties the Cache. Clear() error // Len returns the number of entries in the Cache. Len() int // Stop tells the Cache to stop working. Stop() error }
Cache loads and returns instances by ID and caches them in memory.
type Cacheable ¶
type Cacheable interface { // ID returns the identifier of the information. ID() string // IsOutdated checks if their's a newer version of the Cacheable. IsOutdated() (bool, error) // Discard tells the Cacheable to clean up itself. Discard() error }
Cacheable defines the interface for all cacheable information.
type CacheableLoader ¶
CacheableLoader allows the user to define a function for loading/reloading of cacheable instances.
func NewFileLoader ¶
func NewFileLoader(root string, maxSize int64) CacheableLoader
NewFileLoader returns a CacheableLoader for files. It starts at the given root directory.
type FileCacheable ¶
type FileCacheable interface { Cacheable // ReadCloser returns the io.ReadCloser for the // cached file or the file itself if it's too large. ReadCloser() (io.ReadCloser, error) }
FileCacheable contains a file.