Im trying to tell Gradle to clean up any cache key...
# caching
r
Im trying to tell Gradle to clean up any cache keys that were not part of the active run. My understanding is I can put something like this into `~/.gradle/init.d/cache-settings.gradle.kts`:
Copy code
beforeSettings {
    caches {
        releasedWrappers.setRemoveUnusedEntriesAfterDays(45)
        snapshotWrappers.setRemoveUnusedEntriesAfterDays(10)
        downloadedResources.setRemoveUnusedEntriesAfterDays(45)
        createdResources.setRemoveUnusedEntriesAfterDays(10)
        buildCache.setRemoveUnusedEntriesAfterDays(5)
    }
}
However when I set those values to
0
days (so I can clean up anything before the current session), it errors saying I should use the
setRemoveUnusedEntriesOlderThan
API. Is there any example or documentation on using this new method? It doesn't seem to resolve in my 8.10.2 version of Gradle.
Actually this seems to work now:
Copy code
import java.time.ZonedDateTime
import java.time.ZoneId

beforeSettings { settings ->
    def now = ZonedDateTime.now(ZoneId.of("UTC"))
    settings.caches {
        markingStrategy = MarkingStrategy.NONE
        cleanup = Cleanup.ALWAYS
        releasedWrappers.removeUnusedEntriesOlderThan = now.toInstant().toEpochMilli()
        snapshotWrappers.removeUnusedEntriesOlderThan = now.toInstant().toEpochMilli()
        downloadedResources.removeUnusedEntriesOlderThan = now.toInstant().toEpochMilli()
        createdResources.removeUnusedEntriesOlderThan = now.toInstant().toEpochMilli()
    }
}
Open to feedback though if this is a terrible approach.