EvictStaleCachedResponsesJob.java

1
package edu.ucsb.cs156.diningcachingproxy.jobs;
2
3
import edu.ucsb.cs156.diningcachingproxy.collections.CachedResponseRepository;
4
import edu.ucsb.cs156.jobs.services.JobContext;
5
import edu.ucsb.cs156.jobs.services.JobContextConsumer;
6
import java.time.Instant;
7
import lombok.Builder;
8
9
/**
10
 * Deletes every cached response not accessed since {@code cutoff}. Many upstream paths are
11
 * date-parameterized (e.g. {@code /dining/menu/v1/2026-08-23/carrillo}) and are almost never
12
 * requested again once their date passes, so without this the cache collection would grow without
13
 * bound. Run via {@code JobService} so each run (and how much it deleted) is visible at {@code
14
 * /api/jobs}.
15
 */
16
@Builder
17
public class EvictStaleCachedResponsesJob implements JobContextConsumer {
18
19
  private CachedResponseRepository cachedResponseRepository;
20
  private Instant cutoff;
21
22
  @Override
23
  public void accept(JobContext ctx) throws Exception {
24 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
    ctx.log("Evicting cached responses not accessed since " + cutoff);
25
    long deleted = cachedResponseRepository.deleteNotAccessedSince(cutoff);
26 1 1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED
    ctx.log("Evicted " + deleted + " cached response(s)");
27
  }
28
}

Mutations

24

1.1
Location : accept
Killed by : edu.ucsb.cs156.diningcachingproxy.jobs.EvictStaleCachedResponsesJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.jobs.EvictStaleCachedResponsesJobTests]/[method:deletes_entries_not_accessed_since_the_cutoff_and_logs_the_count()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

26

1.1
Location : accept
Killed by : edu.ucsb.cs156.diningcachingproxy.jobs.EvictStaleCachedResponsesJobTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.diningcachingproxy.jobs.EvictStaleCachedResponsesJobTests]/[method:deletes_entries_not_accessed_since_the_cutoff_and_logs_the_count()]
removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1