Refactor ThumbnailsCacheManager to reduce repeated code