Repository: square/okhttp
File: okhttp/src/commonJvmAndroid/kotlin/okhttp3/Cache.kt (Kotlin)

Code before:
      this.requestMethod = response.request.method
      this.protocol = response.protocol
      this.code = response.code
      this.message = response.message
      this.responseHeaders = response.headers
      this.handshake = response.handshake
      this.sentRequestMillis = response.sentRequestAtMillis
      this.receivedResponseMillis = response.receivedResponseAtMillis
    }

    @Throws(IOException::class)
    fun writeTo(editor: DiskLruCache.Editor) {
      editor.newSink(ENTRY_METADATA).buffer().use { sink ->
        sink.writeUtf8(url.toString()).writeByte('\n'.code)
        sink.writeUtf8(requestMethod).writeByte('\n'.code)
        sink.writeDecimalLong(varyHeaders.size.toLong()).writeByte('\n'.code)
        for (i in 0 until varyHeaders.size) {
          sink
            .writeUtf8(varyHeaders.name(i))
            .writeUtf8(": ")
            .writeUtf8(varyHeaders.value(i))
            .writeByte('\n'.code)
        }

        if (requestMethod == "QUERY") {
          // Write the body of a QUERY request.
          if (body == null) {
            // Should not happen, but if it does, write a -1 to indicate no body.
            sink.writeDecimalLong(-1L).writeByte('\n'.code)
          } else {
            sink.writeDecimalLong(body.contentLength())
            body.writeTo(sink)
            sink.writeByte('\n'.code)
          }
        } else {
          // Write the body of a GET request.
          sink.writeDecimalLong(-1L).writeByte('\n'.code)
        }
        sink.writeUtf8(StatusLine(protocol, code, message).toString()).writeByte('\n'.code)
        sink.writeDecimalLong((responseHeaders.size + 2).toLong()).writeByte('\n'.code)
        for (i in 0 until responseHeaders.size) {
          sink
            .writeUtf8(responseHeaders.name(i))
            .writeUtf8(": ")
            .writeUtf8(responseHeaders.value(i))
            .writeByte('\n'.code)
        }
        sink
          .writeUtf8(SENT_MILLIS)
          .writeUtf8(": ")
          .writeDecimalLong(sentRequestMillis)

Review comment (performance):
Do we need to store the request body in cache? 

Looking at the code, it looks like storing a request in the cache is already destructive as only the `vary` headers of the request are stored (not all of them). 

I think I wouldn't mind too much if `Cache.Entry.body` was missing and saving some bytes there. 

Code after:
    @Throws(IOException::class)
    fun writeTo(editor: DiskLruCache.Editor) {
      editor.newSink(ENTRY_METADATA).buffer().use { sink ->
        sink.writeUtf8(url.toString()).writeByte('\n'.code)
        sink.writeUtf8(requestMethod).writeByte('\n'.code)
        sink.writeDecimalLong(varyHeaders.size.toLong()).writeByte('\n'.code)
        for (i in 0 until varyHeaders.size) {
          sink
            .writeUtf8(varyHeaders.name(i))
            .writeUtf8(": ")
            .writeUtf8(varyHeaders.value(i))
            .writeByte('\n'.code)
        }

        sink.writeUtf8(StatusLine(protocol, code, message).toString()).writeByte('\n'.code)
        sink.writeDecimalLong((responseHeaders.size + 2).toLong()).writeByte('\n'.code)
        for (i in 0 until responseHeaders.size) {
          sink
            .writeUtf8(responseHeaders.name(i))
            .writeUtf8(": ")
            .writeUtf8(responseHeaders.value(i))
            .writeByte('\n'.code)
        }
        sink
          .writeUtf8(SENT_MILLIS)
          .writeUtf8(": ")
          .writeDecimalLong(sentRequestMillis)
          .writeByte('\n'.code)
        sink
          .writeUtf8(RECEIVED_MILLIS)
          .writeUtf8(": ")
          .writeDecimalLong(receivedResponseMillis)
          .writeByte('\n'.code)

        if (url.isHttps) {
          sink.writeByte('\n'.code)
          sink.writeUtf8(handshake!!.cipherSuite.javaName).writeByte('\n'.code)
          writeCertList(sink, handshake.peerCertificates)
          writeCertList(sink, handshake.localCertificates)
          sink.writeUtf8(handshake.tlsVersion.javaName).writeByte('\n'.code)
        }
      }
    }

    @Throws(IOException::class)
    private fun readCertificateList(source: BufferedSource): List<Certificate> {
      val length = readInt(source)
      if (length == -1) return emptyList() // OkHttp v1.2 used -1 to indicate null.

      try {
        val certificateFactory = CertificateFactory.getInstance("X.509")