private function compareCacheAndSqlEntities(bool $doRefresh) : array
    {
        // If there was an issue grabbing all entities in cache, null will be returned
        $unkeyedCacheEntities = $this->cacheDataMapper->getAll();

        if ($unkeyedCacheEntities === null) {
            $unkeyedCacheEntities = [];
        }

        $cacheEntities = $this->keyEntityArray($unkeyedCacheEntities);
        $sqlEntities = $this->keyEntityArray($this->sqlDataMapper->getAll());
        $unsyncedEntities = [
            'missing' => [],
            'differing' => [],
            'additional' => []
        ];

        // Compare the entities in the SQL database to those in cache
        foreach ($sqlEntities as $sqlId => $sqlEntity) {
            if (isset($cacheEntities[$sqlId])) {
                // The entity appears in cache
                $cacheEntity = $cacheEntities[$sqlId];

                if ($sqlEntity != $cacheEntity) {
                    $unsyncedEntities['differing'][] = $sqlEntity;

                    if ($doRefresh) {
                        // Sync the entity in cache with the one in SQL
                        $this->cacheDataMapper->delete($cacheEntity);
                        $this->cacheDataMapper->add($sqlEntity);
                    }
                }
            } else {
                // The entity was not in cache
                $unsyncedEntities['missing'][] = $sqlEntity;

                if ($doRefresh) {
                    // Add the entity to cache
                    $this->cacheDataMapper->add($sqlEntity);
                }
            }
        }

        // Find entities that only appear in cache
        $cacheOnlyIds = array_diff(array_keys($cacheEntities), array_keys($sqlEntities));

        foreach ($cacheOnlyIds as $entityId) {
            $cacheEntity = $cacheEntities[$entityId];
            $unsyncedEntities['additional'][] = $cacheEntity;

            if ($doRefresh) {
                // Remove the entity that only appears in cache
                $this->cacheDataMapper->delete($cacheEntity);
            }
        }

        return $unsyncedEntities;
    }