---
title: "CacheDrawScope"
description: "Handle to a drawing environment that enables caching of content based on the resolved size.
Consumers define parameters and refer to them in the captured draw callback provided in
[onDrawBehind] or [onDrawWithContent].

[onDrawBehind] will draw behind the layout's drawing contents however, [onDrawWithContent] will
provide the ability to draw before or after the layout's contents"
type: "class"
---

<div class='type'>Class</div>


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

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


```kotlin
class CacheDrawScope internal constructor() : Density
```


Handle to a drawing environment that enables caching of content based on the resolved size.
Consumers define parameters and refer to them in the captured draw callback provided in
`onDrawBehind` or `onDrawWithContent`.

`onDrawBehind` will draw behind the layout's drawing contents however, `onDrawWithContent` will
provide the ability to draw before or after the layout's contents


## Properties

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


```kotlin
val size: Size
```


Provides the dimensions of the current drawing environment



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


```kotlin
val layoutDirection: LayoutDirection
```


Provides the `LayoutDirection`.



## Functions

```kotlin
fun obtainGraphicsLayer(): GraphicsLayer
```


Returns a managed `GraphicsLayer` instance. This `GraphicsLayer` maybe newly created or
return a previously allocated instance. Consumers are not expected to release this instance
as it is automatically recycled upon invalidation of the CacheDrawScope and released when the
`DrawCacheModifier` is detached.


```kotlin
fun obtainShadowContext(): ShadowContext
```


Returns the `ShadowContext` used to create `InnerShadowPainter` and `DropShadowPainter` to
render inner and drop shadows respectively


```kotlin
fun GraphicsLayer.record(
        density: Density = this@CacheDrawScope,
        layoutDirection: LayoutDirection = this@CacheDrawScope.layoutDirection,
        size: IntSize = this@CacheDrawScope.size.toIntSize(),
        block: ContentDrawScope.() -> Unit,
    )
```


Record the drawing commands into the `GraphicsLayer` with the `Density`, `LayoutDirection`
and `Size` are given from the provided `CacheDrawScope`


```kotlin
fun onDrawBehind(block: DrawScope.() -> Unit): DrawResult
```


Issue drawing commands to be executed before the layout content is drawn


```kotlin
fun onDrawWithContent(block: ContentDrawScope.() -> Unit): DrawResult
```


Issue drawing commands before or after the layout's drawing contents



