@@ -0,0 +1,2924 @@
+package uk.ac.ebi.quickgo.rest.cache;%0A%0Aimport java.time.Duration;%0Aimport java.time.LocalTime;%0Aimport java.util.function.Supplier;%0A%0A/**%0A * This algorithm models the following situation - Start time of caching after end time. So the start time of caching%0A * is occurs in one day, the end of the caching in the next. Here are the situations this class must deal with%0A *%0A * Before End Time: We are approaching the time of day when the data we use to populate requests is going to be%0A * refreshed, therefore any subsequent requests to a RESTful service should have the following  header%0A * %3Ccode%3Ecache-control: max-age=0%3C/code%3E%0A * so User Agents or gateway caches don't cache this information (as it is likely to be out of data soon).%0A *%0A * After Start Time - we have high confidence data refresh will have taken place, and will not take place again until%0A * after the end time the next day. Calculate the time left (in seconds) between a call to this method and Time A,%0A * and set the cache-control header so this data can be cached by UAs, or gateway caches for this period. The response%0A * HTTP header will be the following:%0A * %3Ccode%3Ecache-control: max-age=36000%3C/code%3E%0A * if there is exactly ten hours left between a call to this method and Time A.%0A *%0A * After End Time and before Start Time: We are around the indexing time. We tell all respondents not to cache - max%0A * age is set to zero.%0A *%0A * See %3Ca href=%22https://jakearchibald.com/2016/caching-best-practices/%22%3ECaching best practices & max-age%0A * gotchas%3C/a%3E,%0A * %3Ca href=%22https://www.mnot.net/cache_docs/%22%3ECaching Tutorial for Web Authors and Webmasters%3C/a%3E,%0A * %3Ca href=%22https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers%22%3EIncreasing Application Performance with HTTP Cache Headers %7C Heroku Dev Center%3C/a%3E%0A *%0A * @return a String that holds the number of seconds left before the cut-off time after which requests will not be%0A * cached.%0A *%0A * @author Tony Wardell%0A * Date: 10/04/2017%0A * Time: 15:53%0A * Created with IntelliJ IDEA.%0A */%0Apublic class MaxAgeWhenStartTimeAfterEndTime implements Supplier%3CDuration%3E %7B%0A%0A    private LocalTime start, end;%0A%0A    public MaxAgeWhenStartTimeAfterEndTime(LocalTime start, LocalTime end) %7B%0A        this.start = start;%0A        this.end = end;%0A    %7D%0A%0A    @Override public Duration get() %7B%0A        Duration remaining;%0A        final LocalTime now = LocalTime.now();%0A        if (now.isAfter(start)) %7B%0A            Duration durationLeftToday = Duration.between(now, LocalTime.MAX);%0A            Duration durationTomorrow = Duration.between(LocalTime.MIN, end);%0A            remaining = durationLeftToday.plus(durationTomorrow);%0A        %7D else %7B%0A            if (now.isBefore(end)) %7B%0A                remaining = Duration.between(now, end);%0A            %7D else %7B%0A                remaining = Duration.ZERO;%0A            %7D%0A        %7D%0A        assert !remaining.isNegative();%0A        return remaining;%0A    %7D%0A%7D%0A

Create a class to hold max age calculation when start time for caching availability is the day before the end caching time - i.e. the caching availability period runs overnight.