DRY code to remove cache entries

Signed-off-by: Simon Leung <leungs@us.ibm.com>
Clarify logic for moving downloaded files into cache

Signed-off-by: Max Brunsfeld <mbrunsfeld@pivotallabs.com>
Move caching logic into a separate file

Signed-off-by: Max Brunsfeld <mbrunsfeld@pivotallabs.com>