I don’t get your point, you’re generating an hash with the query parameters, thus including “order” and “orderby” parameters.
With my edits the cache works exactly as before; in fact you’re sorting the attachments only after the DB query has been executed.
Another reason would to keep in cache the attachments not regarding their sorting; in that case you should create the cache hash without the two “order” and “orderby” paramseters.
Regards