Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouple cache invalidation criteria
- Loading branch information
Showing
8 changed files
with
165 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
sonar-home/src/main/java/org/sonar/home/cache/PersistentCacheInvalidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.home.cache; | |||
|
|||
import java.io.IOException; | |||
import java.nio.file.Path; | |||
|
|||
public interface PersistentCacheInvalidation { | |||
boolean test(Path cacheEntryPath) throws IOException; | |||
} |
48 changes: 48 additions & 0 deletions
48
sonar-home/src/main/java/org/sonar/home/cache/TTLCacheInvalidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* SonarQube is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.home.cache; | |||
|
|||
import java.io.IOException; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.nio.file.attribute.BasicFileAttributes; | |||
|
|||
public class TTLCacheInvalidation implements PersistentCacheInvalidation { | |||
private final long durationToExpireMs; | |||
|
|||
public TTLCacheInvalidation(long durationToExpireMs) { | |||
this.durationToExpireMs = durationToExpireMs; | |||
} | |||
|
|||
@Override | |||
public boolean test(Path cacheEntryPath) throws IOException { | |||
BasicFileAttributes attr = Files.readAttributes(cacheEntryPath, BasicFileAttributes.class); | |||
long modTime = attr.lastModifiedTime().toMillis(); | |||
|
|||
long age = System.currentTimeMillis() - modTime; | |||
|
|||
if (age > durationToExpireMs) { | |||
return true; | |||
} | |||
|
|||
return false; | |||
} | |||
|
|||
} |
82 changes: 0 additions & 82 deletions
82
sonar-home/src/main/java/org/sonar/home/cache/UnlockOnCloseInputStream.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.