Documentation
¶
Overview ¶
Package fcache provides named cache for functions results
supported functions are:
- Output for OutPutters: Output() ([]byte, error)
cache backend is filesystem directory, and functions are protected by a Lock/Unlock lock := func(name string) Locker
Index ¶
- func Age(sig string, dir string, lockDuration time.Duration, ...) (time.Duration, error)
- func Clear(sig string, dir string, lockDuration time.Duration, ...) error
- func Output(o Outputter, sig string, dir string, lockDuration time.Duration, ...) (out []byte, err error)
- func Purge(cacheDir string) (err error)
- type Locker
- type Outputter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Age ¶ added in v1.1.0
func Age(sig string, dir string, lockDuration time.Duration, lockP func(name string) Locker) (time.Duration, error)
Age returns the duration between the cache file modification time and now.
func Output ¶
func Output(o Outputter, sig string, dir string, lockDuration time.Duration, lockP func(name string) Locker) (out []byte, err error)
Output function returns previous o.Output() results named 'sig' from 'cacheDir', if not found in cache a new value is computed, and cache is updated.
A lock object associated with 'sig' (created by function 'lockP') is used,
When lock error:
Returns o.Output() (no update cache).
When locked:
returns found cache entry associated with 'sig' from 'cacheDir'. If entry is not present, it runs 'o.Output()'. In case of error during o.Output(), the error is returned and cache is not updated, else cache associated with 'sig' is updated and new cached value is returned.
dir is created if absent, lockDuration is the maximum duration to wait for lock step.
Types ¶
Click to show internal directories.
Click to hide internal directories.