Caching API / DB queries
When running a query, you can cache results of certain parts to speed up the query, and remove redundant requests to databases / APIs.
Cache purging
Right now, cache will survive between queries, and the only way to purge it is to restart the process running RapidQL.
There are plans to add future support for request limited cache, and TTL for cached data.
To use cache for a certain call, add an asterisk ("*") before it:
{
*Http.get(url:"http://httpbin.org/ip") {
origin
}
}
The cache will trigger if the same function is called again with the same arguments exactly, meaning in the following example:
{
*Http.get(url:"http://api111.com/") {
data
},
*Http.get(url:"http://api111.com/") {
data
},
*Http.get(url:"http://api222.com/") {
data
}
}
The first request to api111 will cache, and that cache will be used by the second call, but the third call to api222 will not use the cache as it has different arguments.
Using cache is recommended when traversing large arrays of data to append information, where the data can be repetitive and does not change (for instance, if you're traversing a CSV of song listen, adding data related to the songs, and each song can have many listens).
In these scenarios, using cache can:
- Reduce the amount of API requests made
- Speed up the query
Memory consumption
All cached results are saved in memory for the duration of the process running. Notice that if you keep RapidQL running for long, memory consumption will grow over time with each cached result.
Also, if your query will cache a lot of data, it'll all be held in memory.
There are future plans to support databases like Redis and Memchached for longer running RapidQL processes and for sharing cache.
Updated over 5 years ago