Optimize checking whether a resource (image or nzb file) is already in the cache by issueing 1 query at each iteration instead of close to 2000 queries.