Skip to main content

Tuning Cache Detection

Cache detection is an optimization feature that can significantly improve your macro's performance by reducing the number of screen captures required during execution.

Understanding Cache Detection

By default, your macro captures the screen every time it needs to perform text or image detection. While this ensures accuracy, it can be computationally intensive. Cache detection allows you to store and reuse the last captured frame, reducing the overhead of repeated screen captures.

Using Cache Settings

Enabling Cache

# turn cache on
Settings:cacheOn();

When cache is enabled:

  • The macro stores the last captured frame in temporary memory
  • Subsequent detection operations use the cached frame instead of capturing a new one
  • Significantly reduces CPU and memory usage during rapid detection operations

Disabling Cache

# turn cache off
Settings:cacheOff();

When cache is disabled:

  • The macro captures a new frame for each detection operation
  • Provides the most up-to-date screen information
  • Useful when the screen content changes frequently

Best Practices

  1. Enable cache when:

    • Performing multiple detections in quick succession
    • The screen content remains relatively static
    • Performance optimization is a priority
  2. Disable cache when:

    • Screen content changes rapidly
    • Absolute detection accuracy is required
    • Memory usage is a concern

Example Usage

# Enable cache for a sequence of related detections
Settings:cacheOn();
Screen:find('Button 1.jpg');
Screen:find('Button 2.jpg');
Screen:find('Button 3.jpg');

# Disable cache when done
Settings:cacheOff();

You can combine cache detection with other optimization settings:

  • Settings:grayscaleOn() - Further improve performance by processing in grayscale
  • Settings:setScanInterval() - Add delays between detection operations
  • Settings:setMinScore() - Adjust detection accuracy threshold