<div class='type'>Compose Modifier</div>

<a id='references'></a>


<h2 id="drawwithcache-onbuilddrawcache">drawWithCache</h2>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun Modifier.drawWithCache(onBuildDrawCache: CacheDrawScope.() -> DrawResult) =
    this then DrawWithCacheElement(onBuildDrawCache)
```


Draw into a `DrawScope` with content that is persisted across draw calls as long as the size of
the drawing area is the same or any state objects that are read have not changed. In the event
that the drawing area changes, or the underlying state values that are being read change, this
method is invoked again to recreate objects to be used during drawing

For example, a `androidx.compose.ui.graphics.LinearGradient` that is to occupy the full bounds of
the drawing area can be created once the size has been defined and referenced for subsequent draw
calls without having to re-allocate.