MDL-47832 cache: data source aggregation fixes

The data source aggregate feature (which is advanced) has been
very broken for several releases.
As it still has potential use cases we decided to keep it instead
or getting rid of it.
The changes made here include:

* Getting data source aggregates working.
* Better commenting about data source aggregates.
* Consistent naming of args and variables.
* Unit tests to cover its expected operation.