Currently the Python related cache contents are always restored to the build directory, even if the contents are going to be invalidated/deleted later, which (a) wastes time copying files that aren't used, (b) leads to the current mess of the cache handling throughout the buildpack mixing and matching cache dir vs build dir references.
We should perform cache invalidation up front (against the files in their cache dir location), and only if we're reusing the caches content should it be copied back to the build directory.
Note: Making this change will require moving cache restoration to after the bin/pre_compile hook stage, since the cache handling depends on the package manager and Python version calculation steps having already been performed (which themselves must occur after the bin/pre_compile hook, so that it can write out package manager files if needed etc).
Currently the Python related cache contents are always restored to the build directory, even if the contents are going to be invalidated/deleted later, which (a) wastes time copying files that aren't used, (b) leads to the current mess of the cache handling throughout the buildpack mixing and matching cache dir vs build dir references.
We should perform cache invalidation up front (against the files in their cache dir location), and only if we're reusing the caches content should it be copied back to the build directory.
Note: Making this change will require moving cache restoration to after the
bin/pre_compilehook stage, since the cache handling depends on the package manager and Python version calculation steps having already been performed (which themselves must occur after thebin/pre_compilehook, so that it can write out package manager files if needed etc).