Writes reset the cache
Save, update or delete rows through API Maker and every cached read of that table is removed. An update or delete also clears cached tables whose schema points to it.
API Maker
The framework for AI era
Performance
One setting, and repeat reads come from Redis instead of your database.
Turn on enableCaching for a database, a table or an API. API Maker keeps each response in Redis, answers the same request from there, and removes the cached reads of a table as soon as it is written through API Maker. You write no caching code.
Step through it, slow it down, or open the full canvas.
Caching is one setting. Set enableCaching: true in the settings of a database or a table, or of a custom or system API. No caching code to write.
Set enableCaching: true in the settings of a database or a table, or of a custom or system API. No caching code to write.
The key is the table plus a hash of the request and its API user. On a miss, API Maker reads the database and keeps the response in Redis.
The same request is answered straight from Redis, with the header x-am-data-source: cache. The database is not touched.
Insert, update or delete through API Maker, and every cached read of products is removed. The next read gets the new price.
The API user is part of the key, so users with different field access never share a response. Keys expire after 7200 s.
Send x-am-cache-control: reset_cache to force a fresh read, or call g.sys.cache.resetCacheDB from your code.
Save, update or delete rows through API Maker and every cached read of that table is removed. An update or delete also clears cached tables whose schema points to it.
The API user is part of the cache key, so users with different field access never get each other's response.
A cached custom API can list the tables and APIs it depends on in resetCacheOnModificationOf. When one of them changes, its cache is cleared.
Every response carries x-am-data-source: cache or api, so you always know if the database was read.
Send x-am-cache-control: reset_cache to force a fresh read, or call g.sys.cache.resetCacheDB, resetCacheCustomApis or resetCacheSystemApis from your code.
With multi-tenant instances the tenant is part of the key, so one customer never receives the cache of another.
Thousands of visitors open the same category pages, while prices change a few times a day. With caching on the products table, the pages are served from Redis, and the moment someone updates a price through the API the cached pages of that table are dropped. The next visitor sees the new price.
import * as T from 'types';let instanceColSetting: T.IInstanceApiSettingsTypes = { enableCaching: true,};module.exports = instanceColSetting;import * as T from 'types';let customApi: T.ICustomApiSettingsTypes = { name: 'Top Products', requestMethod: T.ERequestMethod.GET, path: '/top-products', enableCaching: true, resetCacheOnModificationOf: [ 'DB:shop:main:products', // a write to this table clears the cache of this API ], errorList: [],};module.exports = customApi;await g.sys.cache.resetCacheDB({ instance: 'shop', database: 'main', collection: 'products',});The read APIs of a table with caching on: get all, get by id, query, aggregate, count and distinct. Custom and system APIs are cached when their own settings have enableCaching: true.
The table (or API), the tenant if any, and a hash of the API user, the request body, query and parameters, and the headers that change the answer: content type, secret, response format, key case, flattening and encryption.
Look at the x-am-data-source response header: cache means Redis answered, api means the API ran.
Yes. redisValueExpireInSeconds in the redisExternal settings sets how long keys live. The default is 7200 seconds.