Midscene supports caching the planning steps and DOM XPaths to reduce calls to AI models and greatly improve execution efficiency.
Caching is not supported in Android automation.
Effect
After enabling the cache, the execution time of AI service related steps can be significantly reduced.
There are two key points to use caching:
MIDSCENE_CACHE=1
in the environment variable to enable matching cache.cacheId
to specify the cache file name. It's automatically set in Playwright and Yaml mode. If you are using javascript SDK, you should set it manually.In playwright mode, you can use the MIDSCENE_CACHE=1
environment variable to enable caching.
The cacheId
will be automatically set to the test file name.
Enable caching by setting the MIDSCENE_CACHE=1
environment variable.
And also, you should set the cacheId
to specify the cache identifier.
Enable caching by setting the MIDSCENE_CACHE=1
environment variable.
The cacheId
will be automatically set to the yaml filename.
Cache contents will be saved in the ./midscene_run/cache
directory with the .cache.yaml
as the extension name.
These two types of content will be cached:
.ai
.aiAction
.aiLocate
, .aiTap
, etc.The query results like aiBoolean
, aiQuery
, aiAssert
will never be cached.
If the cache is not hit, Midscene will call AI model again and the result in cache file will be updated.
You can view the report file. If the cache is hit, you will see the cache
tip and the time cost is obviously reduced.
You should commit the cache file to the repository (which is in the ./midscene_run/cache
directory). And also, check whether the prompt is the same as the one in the cache file.
No. Caching is the way to accelerate the execution, but it's not a tool for ensuring long-term script stability. We have noticed many scenarios where the cache may miss when the DOM structure changes. AI services are still needed to reevaluate the task when the cache miss occurs.
You can remove the cache file in the cache
directory, or edit the contents in the cache file.