> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dairy.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# Intro to Cells + RefCell

Cells are Dairy's shared interior mutability reference wrapper.
This sounds complicated, but its not.
Cells basically allow you to wrap some data with a common access interface.

The most basic cell you could use is the `RefCell`. We'll use [Units](./units)
as our inner contents.

<CodeGroup>
  ```java Java theme={null}
  RefCell<Distance> millimeters = new RefCell<>(Distances.mm(10)); // this RefCell contains a Distance
  ```

  ```kt Kotlin theme={null}
  val millimeters: RefCell<Distance> = RefCell(10.mm) // this RefCell contains a Distance
  ```
</CodeGroup>

The contents of a Cell are often referred to as the 'contents' or the 'ref'
(short for reference).
We can access the contents like so:

<CodeGroup>
  ```java Java theme={null}
  Distance ten = millimeters.get();
  ```

  ```kt Kotlin theme={null}
  val ten = millimeters.get()
  ```
</CodeGroup>

and we can set the contents like so:

<CodeGroup>
  ```java Java theme={null}
  millimeters.accept(Distances.mm(12));
  ```

  ```kt Kotlin theme={null}
  millimeters.accept(12.mm)
  ```
</CodeGroup>

This is because all Cells implement Consumer and Supplier.
This allows them to be used directly in many places across Dairy, as these two
interfaces are used often.

Additionally, Cells keep track of when access occurred.

<CodeGroup>
  ```java Java theme={null}
  double secondsGet = millimeters.getTimeSincelastGet();
  double secondsSet = millimeters.getTimeSincelastSet();
  double secondsAccess = millimeters.getTimeSinceLastAccess();
  ```

  ```kt Kotlin theme={null}
  val secondsGet: Double = millimeters.timeSincelastGet
  val secondsSet: Double = millimeters.timeSincelastSet
  val secondsAccess: Double = millimeters.timeSinceLastAccess
  ```
</CodeGroup>

Its also worth noting that Cells can be used for delegation in Kotlin:

<CodeGroup>
  ```java Java theme={null}
  public Distance getDistance() {
  	return millimeters.get();
  }
  public void setDistance(Distance distance) {
  	millimeters.accept(distance);
  }
  ```

  ```kt Kotlin theme={null}
  val distance by millimeters
  ```
</CodeGroup>

This means that `distance` is of type `Distance`, and when you get, or set it,
the behaviour is delegated to the millimeters RefCell.

RefCell is useful, but Cells can be extended to have a myriad of other
behaviours, we'll go over some of the more common and useful
