AQL Cache
AQL Cache机制可以对通过AQL查询出来的结果进行缓存。
Modes
- off: 禁用cache,所有的查询结果都不会缓存
- on:开启cache,所有通过AQL查询的结果默认都进行缓存,除非在查询时设置cache attribute 为false
- demand:只在需要时通过设置cache attribute 来控制是否进行缓存
cache mode可以在启动时指定,也可以在运行时指定
设置
全局配置
- 启动时指定 --query.cache-mode 进行配置
- 在运行中,通过arangosh执行
require("@arangodb/aql/cache").properties({ mode: "on" });
修改cache mode
单次请求配置
-
通过arangosh执行db._query()时设置cache,例如:
db.query({ query:"return document('id')", cache:true });
-
通过rest api请求时指定cache,例如
curl -X POST http://localhost:8529/_api/cursor --data '{"query":"return document(\"vertexs/1\")","cache":true}'
缓存结果
- 查询缓存结果
require("@arangodb/aql/cache").toArray();
- 清除缓存结果
require("@arangodb/aql/cache").clear();