Implement more robust caching for master images

This patch introduces caching for master images, which
are no longer used. This patch also introduces clean up procedure,
which is triggered every time cache size increases or link
to master images is deleted. Algorithm is following:
- Images are eligible for deletion, if their link count equals 1.
  Images that has link count >1 are not considered for deletion,
  because it anyway won't reclaim any disk space.
- All images older than configurable TTL are deleted
- Then the oldest images are deleted, until size of cache fits
  into configurable value or no more images eligable for deletion.

As this change required rethinking how we cache images, I also
did a refactor and grouped related functions under ImageCache class.

Change-Id: I1c849fe209c4dbb15e075dbb34c4ea33010a8883
Closes-Bug: #1199665
Merge "Implement more robust caching for master images"