Configuring adhoc cache parameters for Arnica NanoQuery

November 17, 2022 by Igor Lozhkin
Arnica NanoQuery is a pass-through query system which accepts SQL queries using REST web requests, executes queries against remote databases and returns query results as JSON or XML. Queries may be executed in real-time or optionally cached with specified cache lifecycle parameters.

There are two cache types: adhoc and scheduled. 

The adhoc cache triggers its update when the next request comes in after cache has expired. 

The scheduled cache triggers its update based on its own schedule, regardless of activity.

Cache configuration is passed via query string parameter cache, for example:

cache=ttl:3600@max_ttl:7200@idle_timeout:86400@wake:sync@disk@rtt:5,3

Adhoc cache is used when option @interval:nnn is not present or has an empty or 0 value. 

In the example above, cache is configured with expiration time of 3600 seconds. After this time, the next request will trigger cache update. Option @max_ttl:7200 defines grace period, within which cache will still be served as though it is not expired, but the next request will trigger background asynchronous cache update.  

Option @wake:sync specifies the very first time the query is executed. This will initialize a cache instance, but will make the requestor wait for the query to complete before getting results. Option @disk creates a disk copy of the cache instance metadata and data, which is used as a backup to automatically restore the cache instance state when the system is restarted.

With option @idle_timeout:86400, cache is evicted if there are no requests within 86400 seconds since the last request. 

Option @rtt:5,3 (real-time trigger) engages real-time  mode if the SQL query execution during the last cache update is less or equal than 5 seconds. Statistics of the last 3 real-time executions are kept in queue and when average execution time exceeds 5 seconds, real-time mode is disengaged and cached mode is engaged.