@@ -14,6 +14,7 @@ import org.ysb33r.grolifant.api.ExclusiveFileAccess
14
14
15
15
import java.nio.file.Files
16
16
import java.nio.file.Path
17
+ import java.time.Instant
17
18
18
19
import static com.github.jrubygradle.api.gems.GemVersion.gemVersionFromGradleIvyRequirement
19
20
import static com.github.jrubygradle.internal.core.IvyUtils.revisionsAsHtmlDirectoryListing
@@ -106,12 +107,18 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
106
107
grp == this . group
107
108
}
108
109
110
+ protected boolean expired (Path ivyXml ) {
111
+ System . currentTimeMillis()
112
+ Files . notExists(ivyXml) ||
113
+ (Files . getLastModifiedTime(ivyXml). toMillis() + EXPIRY_PERIOD_MILLIS < Instant . now(). toEpochMilli())
114
+ }
115
+
109
116
protected Path getIvyXml (String grp , String name , String version ) throws NotFound {
110
117
if (inGroups(grp)) {
111
118
String revision = getGemQueryRevisionFromIvy(name, version)
112
119
Path ivyXml = ivyFile(grp, name, revision)
113
120
debug " Requested ${ group} :${ name} :${ version} translated to GEM with version ${ revision} "
114
- if (Files . notExists(ivyXml) || refreshDependencies ) {
121
+ if (refreshDependencies || expired(ivyXml) ) {
115
122
try {
116
123
createIvyXml(ivyXml, name, revision)
117
124
} catch (ApiException e) {
@@ -163,6 +170,8 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
163
170
log. debug(text, context)
164
171
}
165
172
173
+ private static final long EXPIRY_PERIOD_MILLIS =
174
+ System . getProperty(' com.github.jrubygradle.cache-expiry-days' , ' 15' ). toInteger() * 24 * 3600 * 1000
166
175
private volatile int refreshDependencies = 0
167
176
private final File localCachePath
168
177
private final GemToIvy gemToIvy
0 commit comments