PerThreadCache: Add static convenience method

Change-Id: Id599161b12c7b0e2c39ed28f01ff769d9f71b91e
This commit is contained in:
Dave Borowitz
2018-04-18 16:17:02 +02:00
parent 81f373de9e
commit f474dbcc78
2 changed files with 8 additions and 7 deletions

View File

@@ -109,14 +109,10 @@ public class DefaultPermissionBackend extends PermissionBackend {
try {
ProjectState state = projectCache.checkedGet(project);
if (state != null) {
PerThreadCache perThreadCache = PerThreadCache.get();
if (perThreadCache == null) {
return projectControlFactory.create(user, state).asForProject().database(db);
}
PerThreadCache.Key<ProjectControl> cacheKey =
PerThreadCache.Key.create(ProjectControl.class, project, user.getCacheKey());
ProjectControl control =
perThreadCache.get(cacheKey, () -> projectControlFactory.create(user, state));
PerThreadCache.getOrCompute(
PerThreadCache.Key.create(ProjectControl.class, project, user.getCacheKey()),
() -> projectControlFactory.create(user, state));
return control.asForProject().database(db);
}
return FailedPermissionBackend.project("not found", new NoSuchProjectException(project));