public function flush(
        int $bulkNumber = 500,
        bool $skipIfLess = false
    ) {
        if (
            $skipIfLess &&
            count($this->elementsToUpdate) < $bulkNumber
        ) {
            return;
        }

        $offset = 0;

        try {
            while (true) {
                $items = array_slice(
                    $this->elementsToUpdate,
                    $offset,
                    $bulkNumber
                );

                if (empty($items)) {
                    break;
                }

                $this->flushItems($items, []);
                $offset += $bulkNumber;
            }

            $this->flushItems([], $this->elementsToDelete);
        } catch (Exception $exception) {
            /*
             * No matter the exception is thrown, cached elements should be
             * deleted
             */
            $this->resetCachedElements();

            throw $exception;
        }

        $this->resetCachedElements();
    }