diff --git a/scm-core/src/main/java/sonia/scm/repository/work/NoneCachingWorkingCopyPool.java b/scm-core/src/main/java/sonia/scm/repository/work/NoneCachingWorkingCopyPool.java
index 9e9859d27f..e5faa4935e 100644
--- a/scm-core/src/main/java/sonia/scm/repository/work/NoneCachingWorkingCopyPool.java
+++ b/scm-core/src/main/java/sonia/scm/repository/work/NoneCachingWorkingCopyPool.java
@@ -29,6 +29,12 @@ import sonia.scm.util.IOUtil;
import javax.inject.Inject;
import java.io.File;
+/**
+ * This is the default implementation for the {@link WorkingCopyPool}. For each requested {@link WorkingCopy} with
+ * {@link #getWorkingCopy(SimpleWorkingCopyFactory.WorkingCopyContext)}, a new directory is requested from the
+ * {@link WorkdirProvider}. This directory is deleted immediately when the context is closed with
+ * {@link #contextClosed(SimpleWorkingCopyFactory.WorkingCopyContext, File)}.
+ */
public class NoneCachingWorkingCopyPool implements WorkingCopyPool {
private final WorkdirProvider workdirProvider;
diff --git a/scm-core/src/main/java/sonia/scm/repository/work/CachingAllWorkingCopyPool.java b/scm-core/src/main/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPool.java
similarity index 64%
rename from scm-core/src/main/java/sonia/scm/repository/work/CachingAllWorkingCopyPool.java
rename to scm-core/src/main/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPool.java
index 190a7bb58a..7033d59772 100644
--- a/scm-core/src/main/java/sonia/scm/repository/work/CachingAllWorkingCopyPool.java
+++ b/scm-core/src/main/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPool.java
@@ -34,16 +34,45 @@ import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-public class CachingAllWorkingCopyPool implements WorkingCopyPool {
+/**
+ * This class is a simple implementation of the {@link WorkingCopyPool} to demonstrate,
+ * how caching can work in the simplest way. For the first time a {@link WorkingCopy} is
+ * requested for a repository with {@link #getWorkingCopy(SimpleWorkingCopyFactory.WorkingCopyContext)},
+ * this implementation fetches a new directory from the {@link WorkdirProvider}.
+ * On {@link #contextClosed(SimpleWorkingCopyFactory.WorkingCopyContext, File)},
+ * the directory is not deleted, buy put into a map with the repository id as key.
+ * When a working copy is requested with {@link #getWorkingCopy(SimpleWorkingCopyFactory.WorkingCopyContext)}
+ * for a repository with such an existing directory, it is taken from the map, reclaimed and
+ * returned as {@link WorkingCopy}.
+ * If for one repository a working copy is requested, while another is in use already,
+ * a second directory is requested from the {@link WorkdirProvider} for the second one.
+ * If a context is closed with {@link #contextClosed(SimpleWorkingCopyFactory.WorkingCopyContext, File)}
+ * and there already is a directory stored in the map for the repository,
+ * the directory from the closed context simply is deleted.
+ *
+ * In general, this implementation should speed up things a bit, but one has to take into
+ * account, that there is no monitoring of diskspace. So you have to make sure, that
+ * there is enough space for a clone of each repository in the working dir.
+ *
+ * Possible enhancements:
+ *
+ *
Monitoring of times
+ *
Allow multiple cached directories for busy repositories (possibly taking initial branches into account)
+ *
Measure allocated disk space and set a limit
+ *
Remove directories not used for a longer time
+ *
Wait for a cached directory on parallel requests
+ *
+ */
+public class SimpleCachingWorkingCopyPool implements WorkingCopyPool {
- private static final Logger LOG = LoggerFactory.getLogger(CachingAllWorkingCopyPool.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SimpleCachingWorkingCopyPool.class);
private final Map workdirs = new ConcurrentHashMap<>();
private final WorkdirProvider workdirProvider;
@Inject
- public CachingAllWorkingCopyPool(WorkdirProvider workdirProvider) {
+ public SimpleCachingWorkingCopyPool(WorkdirProvider workdirProvider) {
this.workdirProvider = workdirProvider;
}
diff --git a/scm-core/src/test/java/sonia/scm/repository/work/CachingAllWorkingCopyPoolTest.java b/scm-core/src/test/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPoolTest.java
similarity index 82%
rename from scm-core/src/test/java/sonia/scm/repository/work/CachingAllWorkingCopyPoolTest.java
rename to scm-core/src/test/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPoolTest.java
index 65c9d02a83..cc45936bb7 100644
--- a/scm-core/src/test/java/sonia/scm/repository/work/CachingAllWorkingCopyPoolTest.java
+++ b/scm-core/src/test/java/sonia/scm/repository/work/SimpleCachingWorkingCopyPoolTest.java
@@ -44,14 +44,14 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith({MockitoExtension.class})
-class CachingAllWorkingCopyPoolTest {
+class SimpleCachingWorkingCopyPoolTest {
private static final Repository REPOSITORY = new Repository("1", "git", "space", "X");
@Mock
WorkdirProvider workdirProvider;
@InjectMocks
- CachingAllWorkingCopyPool cachingAllWorkingCopyPool;
+ SimpleCachingWorkingCopyPool simpleCachingWorkingCopyPool;
@Mock
SimpleWorkingCopyFactory