def begin_transaction
      if @transaction_stack.empty?
        # The new transaction is the top-level transaction. Flush the write
        # buffer to save the current state of all objects.
        flush
      else
        # Save a copy of all objects that were modified during the enclosing
        # transaction.
        @transaction_stack.last.each do |id|
          @transaction_objects[id]._stash(@transaction_stack.length - 1)
        end
      end
      # Push a transaction buffer onto the transaction stack. This buffer will
      # hold a reference to all objects modified during this transaction.
      @transaction_stack.push(::Array.new)
    end
def begin_transaction
      if @transaction_stack.empty?
        # The new transaction is the top-level transaction. Flush the write
        # buffer to save the current state of all objects.
        flush
      else
        # Save a copy of all objects that were modified during the enclosing
        # transaction.
        @transaction_stack.last.each do |id|
          @transaction_objects[id]._stash(@transaction_stack.length - 1)
        end
      end
      # Push a transaction buffer onto the transaction stack. This buffer will
      # hold a reference to all objects modified during this transaction.
      @transaction_stack.push(::Array.new)
    end
Tell the cache to start a new transaction. If no other transaction is
 active, the write cache is flushed before the transaction is started.