Refactor image cache