Skip to content

Commit 7bedfb5

Browse files
committed
Allow ivy.xml files to be expired from cache (#364)
1 parent a0ed2c0 commit 7bedfb5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core-plugin/src/main/groovy/com/github/jrubygradle/internal/core/AbstractIvyXmlProxyServer.groovy

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.ysb33r.grolifant.api.ExclusiveFileAccess
1414

1515
import java.nio.file.Files
1616
import java.nio.file.Path
17+
import java.time.Instant
1718

1819
import static com.github.jrubygradle.api.gems.GemVersion.gemVersionFromGradleIvyRequirement
1920
import static com.github.jrubygradle.internal.core.IvyUtils.revisionsAsHtmlDirectoryListing
@@ -106,12 +107,18 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
106107
grp == this.group
107108
}
108109

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+
109116
protected Path getIvyXml(String grp, String name, String version) throws NotFound {
110117
if (inGroups(grp)) {
111118
String revision = getGemQueryRevisionFromIvy(name, version)
112119
Path ivyXml = ivyFile(grp, name, revision)
113120
debug "Requested ${group}:${name}:${version} translated to GEM with version ${revision}"
114-
if (Files.notExists(ivyXml) || refreshDependencies) {
121+
if (refreshDependencies || expired(ivyXml)) {
115122
try {
116123
createIvyXml(ivyXml, name, revision)
117124
} catch (ApiException e) {
@@ -163,6 +170,8 @@ abstract class AbstractIvyXmlProxyServer implements IvyXmlProxyServer {
163170
log.debug(text, context)
164171
}
165172

173+
private static final long EXPIRY_PERIOD_MILLIS =
174+
System.getProperty('com.github.jrubygradle.cache-expiry-days', '15').toInteger() * 24 * 3600 * 1000
166175
private volatile int refreshDependencies = 0
167176
private final File localCachePath
168177
private final GemToIvy gemToIvy

0 commit comments

Comments
 (0)