Fix #5 by rejecting imagepromise before the are discarded

Rejecting imagepromise before the are discarded fixes issue #5. The
then() function is never called and the cacheSizeInBytes is not set into
an incoherent state.

purgecache was modified for clarity. The loaded property of cachedImage 
was added because it is used later and a typo was fixed.