Documentation
¶
Overview ¶
Package cache keeps recognition results (never audio) so the same file or URL is not paid for twice. Files are keyed by a SHA-256 of their bytes, so a renamed or copied file still hits; URLs are keyed by the URL and expire after 24 hours.
Index ¶
- Constants
- func KeyForFile(path string, endpoint string, params map[string]string) (string, error)
- func KeyForInput(in media.Input, endpoint string, params map[string]string) (string, error)
- func KeyForURL(u string, endpoint string, params map[string]string) string
- type Cache
- func (c *Cache) Clear() error
- func (c *Cache) Close() error
- func (c *Cache) Count() (int, error)
- func (c *Cache) Get(key string) (json.RawMessage, bool)
- func (c *Cache) Put(key string, isURL bool, result json.RawMessage) error
- func (c *Cache) PutEntry(e Entry, isURL bool) error
- func (c *Cache) Recent(limit int) ([]Entry, error)
- func (c *Cache) SetClock(now func() time.Time)
- type Entry
Constants ¶
const ( EndpointStandard = "recognize" EndpointEnterprise = "enterprise" )
Endpoints used in cache keys.
const URLTTL = 24 * time.Hour
URLTTL is how long a URL result stays valid: the audio behind a URL can change.
Variables ¶
This section is empty.
Functions ¶
func KeyForFile ¶
KeyForFile hashes the file's bytes with the endpoint and parameters.
func KeyForInput ¶
KeyForInput keys a media input (file, stdin audio, or URL).
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is the results cache. It is safe for concurrent use.
func (*Cache) Get ¶
func (c *Cache) Get(key string) (json.RawMessage, bool)
Get returns a cached result. URL entries older than URLTTL are misses.
func (*Cache) PutEntry ¶
PutEntry stores a result with its source (path or URL, for display) and endpoint. At defaults to now.