You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: pivot_table_cache_definition.rb
    path of file: ./repos/caxlsx/lib/axlsx/workbook/worksheet
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Axlsx
  # Table
  # @note Worksheet#add_pivot_table is the recommended way to create tables for your worksheets.
  # @see README for examples
  class PivotTableCacheDefinition
    include Axlsx::OptionsParser

    # Creates a new PivotTable object
    # @param [String] pivot_table The pivot table this cache definition is in
    def initialize(pivot_table)
      @pivot_table = pivot_table
    end

    # # The reference to the pivot table data
    # # @return [PivotTable]
    attr_reader :pivot_table

    # The index of this chart in the workbooks charts collection
    # @return
    
    def to_xml_string(str = +'')
      str << '<?xml version="1.0" encoding="UTF-8"?>'
      str << '<pivotCacheDefinition xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '" invalid="1" refreshOnLoad="1" recordCount="0">'
      str << '<cacheSource type="worksheet">'
      str << '<worksheetSource ref="' << pivot_table.range << '" sheet="' << pivot_table.data_sheet.name << '"/>'
      str << '</cacheSource>'
      str << '<cacheFields count="' << pivot_table.header_cells_count.to_s << '">'
      pivot_table.header_cells.each do |cell|
        str << '<cacheField name="' << cell.clean_value << '" numFmtId="0">'
        str <<     '<sharedItems count="0">'
        str <<     '</sharedItems>'
        str << '</cacheField>'
      end
      str << '</cacheFields>'
      str << '</pivotCacheDefinition>'
    end