Voicegain API has 2 levels of grammar caching:
- HTTP cache - this is for GRXML grammars fetched over HTTP. If grammars are served with correct HTTP headers then standard HTTP caching will be used. Otherwise, GRXML specific caching will be used if specified.
- Compiled grammar cache - here the key is an MD5 hash of the content of the grammar, so the slightest change of the content of the grammar will result in recompilation. Compiled grammars are cached for 1 hour.
Standard HTTP Cache
GRXML grammars that have relevant cache related HTTP headers re cached using okhttp on file system. Okhttp library interprets all relevant cache related headers (see for more info here).
There are many Cache control settings in HTTP. We suggested using etag and last-modified and setting them correctly whenever the grammar content is modified. This will keep the number of grammar fetches from the server to a minimum.
Pitfalls
Some issues that can be encountered with HTTP caching are:
- Setting Last-Modified header to some value in the past and not changing it when the content changes. Even if ETag changes, the grammar will not be refreshed in the cache because it will be considered old based on the Last-Modified date.
- Setting Cache-Control: max-age to a short value. When it expires, if the Last-Modified is not changed the cache will not be refreshed and the cached content will be considered stale. It will be evicted only when cache is full or after 1 day.
GRXML specific cache
GRXML standard defines cache related <meta> tag.
We are using this tag to determine if GRXML should be cached and for how long:
<meta http-equiv="Expires" content="0"/>
Comments
0 comments
Please sign in to leave a comment.