Hi,
Is there an option to for a query to renew in the caching layer in the background by a defined interval. For example: the system would look at all cached queries and automatically renew every hour, day, etc. This would keep data fresh in the cache.
hey @psharma0789! I believe you're looking for https://cube.dev/docs/caching#keeping-cache-up-to-date
Hi @vasilev-alex ! This only seems to be for pre aggregations, correct?
This only seems to be for pre aggregations, correct?
Nope! The CRON job technique in the first paragraph would also keep the redis cache fresh as well.
@jcw- I think that the CRON job needs to execute the queries as if the frontend calls them with "renewQuery: true" flag. Is there any example available? I searched enough and couldn't find a solution.
That's right - you would mimic the same queries that your dashboard is making, and include renewQuery: true, as documented here: https://cube.dev/docs/query-format#query-properties
An example of making a query is here: https://cube.dev/docs/@cubejs-client-core#cubejs-api-load
A more specific version of that would be something like this - note that this example is using the client-side library, you'd probably want to do something similar from server-side Node code on a cron schedule, but conceptually this is what is being suggested I believe:
import cubejs from '@cubejs-client/core';
const cubejsApi = cubejs('CUBEJS_TOKEN');
const resultSet = await cubejsApi.load({
measures: ['Stories.count'],
timeDimensions: [{
dimension: 'Stories.time',
dateRange: ['2015-01-01', '2015-12-31'],
granularity: 'month'
}],
renewQuery: true
});
Most helpful comment
That's right - you would mimic the same queries that your dashboard is making, and include
renewQuery: true, as documented here: https://cube.dev/docs/query-format#query-propertiesAn example of making a query is here: https://cube.dev/docs/@cubejs-client-core#cubejs-api-load
A more specific version of that would be something like this - note that this example is using the client-side library, you'd probably want to do something similar from server-side Node code on a cron schedule, but conceptually this is what is being suggested I believe: