/** * Create, cache and return a Node and store it within the owning node. Typical usage: * * * ``` * listview(people) { * cellFormat { * graphic = cache { * hbox { * label("Some large Node graph here") * } * } * } * } * ``` * * Used within a Cell, the cache statement makes sure that the node is only created once per cell during the cell's life time. * This greatly reduces memory and performance overhead and should be used in every situation where * a node graph is created and assigned to the graphic property of a cell. * * Note that if you call this function without a a unique key parameter, you will only ever create a single * cached node for this parent. The use case for this function is mostly to cache the graphic node of a cell, * so for these use cases you don't need to supply a cache key. * * Remember that you can still update whatever you assign to graphic below it on each `cellFormat` update item callback. * * Important: Make sure to not cache hard coded data from the current item this cell represents, as this will change * when the cell is reused to display another item. Either bind to the itemProperty with select, or use `cellCache` instead. */ fun Node.cache(key: Any = "tornadofx.cachedNode", op: EventTarget.() -> T) = properties.getOrPut(key) { op(this) } as T