     length
 
   getAttachments: ->
+    @attachmentCache or @setCachedAttachments(@extractAttachments())
+
+  setCachedAttachments: (attachments = []) ->
+    @attachmentCache = attachments
+
+  extractAttachments: ->
     for piece in @pieces when piece.attachment
       piece.attachment
 

  consolidate: ->
    pieces = []
    pendingPiece = @pieces[0]

    for piece in @pieces[1..]
      if pendingPiece.canBeConsolidatedWithPiece(piece)

        pieces.push(pendingPiece)
        pendingPiece = piece

      if attachment = pendingPiece.attachment
        attachments.push(attachment)

    pieces.push(pendingPiece) if pendingPiece?
    @setCachedAttachments(attachments)
    @pieces = pieces

  findIndexAndOffsetAtPosition: (position) ->
