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

# AggregateCache

<span id="atoti.AggregateCache" />

> atoti.AggregateCache(<br />
>     \*,<br />
>     *capacity*: [int](https://docs.python.org/3/library/functions.html#int),<br />
>     *measures*: [Set](https://docs.python.org/3/library/collections.abc.html#collections.abc.Set)\[HasIdentifier\[MeasureIdentifier] | MeasureIdentifier] | [None](https://docs.python.org/3/library/constants.html#None) = `None`,<br />
> )

Aggregate cache of a [`Cube`](./atoti.Cube#atoti.Cube).

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> from dataclasses import replace
>>> table = session.create_table("Example", data_types={"id": "int"})
>>> cube = session.create_cube(table)
>>> m = cube.measures
```

There is a default cache:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> cube.aggregate_cache
AggregateCache(capacity=100, measures=None)
```

Increasing the capacity and only caching **contributors.COUNT** aggregates:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> cube.aggregate_cache = tt.AggregateCache(
...     capacity=200,
...     measures={m["contributors.COUNT"]},
... )
>>> cube.aggregate_cache
AggregateCache(capacity=200, measures=frozenset({m['contributors.COUNT']}))
```

Changing back to caching all the measures:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> cube.aggregate_cache = replace(cube.aggregate_cache, measures=None)
>>> cube.aggregate_cache
AggregateCache(capacity=200, measures=None)
```

Disabling caching but keeping sharing enabled:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> cube.aggregate_cache = replace(cube.aggregate_cache, capacity=0)
>>> cube.aggregate_cache
AggregateCache(capacity=0, measures=None)
```

Disabling caching and sharing:

```pycon theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
>>> del cube.aggregate_cache
>>> print(cube.aggregate_cache)
None
```

### Attributes

<h4 id="atoti.AggregateCache.capacity">
  *capacity*
</h4>

The capacity of the cache.

* If greater than `0`, this value corresponds to the maximum amount of `{location: measure}` pairs that the cache can hold.
* If `0`, caching is disabled but sharing stays enabled: concurrent queries will share their computed aggregates, but the aggregates will not be stored to be reused in later queries.

<h4 id="atoti.AggregateCache.measures">
  *measures*
</h4>

The measures to cache.

This should typically be the measures that are known to be the most expensive to compute.

If `None`, all measures will be cached.
