<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWindow/cacheImage(in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSWindow(im)cacheImageInRect:"
  },
  "title" : "cacheImage(in:)"
}
-->

# cacheImage(in:)

Stores the window’s raster image from a given rectangle expressed in the window’s base coordinate system.

```
func cacheImage(in rect: NSRect)
```

## Parameters

`rect`

The rectangle representing the image to cache.

## Discussion

This method allows the window to perform temporary drawing, such as a band around the selection as the user drags the mouse, and to quickly restore the previous image by invoking [`restoreCachedImage()`](/documentation/AppKit/NSWindow/restoreCachedImage()) and [`flushIfNeeded()`](/documentation/AppKit/NSWindow/flushIfNeeded()). The next time the window displays, it discards its cached image rectangles. You can also explicitly use [`discardCachedImage()`](/documentation/AppKit/NSWindow/discardCachedImage()) to free the memory occupied by cached image rectangles. `rect` is made integral before caching the image to avoid antialiasing artifacts.

Only the last cached rectangle is remembered and can be restored.

## See Also

[`display()`](/documentation/AppKit/NSWindow/display())

Passes a display message down the window’s view hierarchy, thus redrawing all views within the window.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)