}
public boolean apply(Jobs jobs) {
for (ListIterator<JobEnvelope> it = jobs.getJobs().listIterator();
it.hasNext();) {
JobEnvelope env = it.next();
// The JS optimization stage is the computationally expensive stage, so
// we lookup pre-optimized version of JS jobs from the cache.
if (env.fromCache || env.job.getType() != ContentType.JS
|| env.job.getRoot().getAttributes().is(JobCache.NO_CACHE)) {
continue;
}
Job job = env.job;
JobCache.Key key = cache.forJob(job.getType(), job.getRoot());
List<? extends Job> fromCache = cache.fetch(key);
if (fromCache != null) {
System.out.println("jobcache hit " + key);
it.remove();
for (Job cacheJob : fromCache) {
JobEnvelope replacement = new JobEnvelope(
// Use the placeholder from the original.
// Placeholders are not part of the cache.
env.placeholderId,
// For cached jobs, we don't need a key since we're not going to
// put them back.
env.cacheKeys,
// The source type from the original.
env.sourceType,
// It came from the cache.
true,
// The cache is responsible for returning a copy that we can
// mutate.
cacheJob);
it.add(replacement);
}
} else {
it.set(new JobEnvelope(
env.placeholderId, key.asSingleton(), env.sourceType, false, job));
}
}
return jobs.hasNoFatalErrors();
}