How to rewrite a simple doLast task to be cacheable?

I see this which isn’t cacheable

task unpackTorBinaries {
	doLast {
		copy {
			from configurations.tor.collect { zipTree(it) }
			into torBinariesDir
			// TODO: Remove after next Tor upgrade, which won't include non-PIE binaries
			include 'geoip.zip', '*_pie.zip'
		}
	}
	dependsOn cleanTorBinaries
}

You could could change to this which is cacheable

task unpackTorBinaries(type: Copy) {
   from configurations.tor.collect { zipTree(it) }
   into torBinariesDir
   include 'geoip.zip', '*_pie.zip'   
   doFirst {
      delete torBinariesDir
   } 
} 

Or perhaps if unzipping is expensive and you want to delay until execution phase

task unpackTorBinaries {
   inputs.files configurations.tor
   outputs.dir torBinariesDir
   doLast {
      delete torBinariesDir
      copy {
         from configurations.tor.collect { zipTree(it) }
         into torBinariesDir
         include 'geoip.zip', '*_pie.zip'   
      }      
   } 
} 

See Feature Request: Unzip Task