Invalid cost calculation when saving image to memory cache