Class SimpleCachingWorkingCopyPool

java.lang.Object
sonia.scm.repository.work.SimpleCachingWorkingCopyPool
All Implemented Interfaces:
WorkingCopyPool

@Singleton public class SimpleCachingWorkingCopyPool extends Object implements WorkingCopyPool
This class is a simple implementation of the WorkingCopyPool to demonstrate, how caching can work in an LRU style. For the first time a WorkingCopy is requested for a repository with getWorkingCopy(SimpleWorkingCopyFactory.WorkingCopyContext), this implementation fetches a new directory from the WorkdirProvider. On contextClosed(SimpleWorkingCopyFactory.WorkingCopyContext, File), the directory is not deleted, but put into a cache with the repository id as key. When a working copy is requested with getWorkingCopy(SimpleWorkingCopyFactory.WorkingCopyContext) for a repository with such an existing directory, it is taken from the map, reclaimed and returned as WorkingCopy. If for one repository a working copy is requested, while another is in use already, the process will wait until the other process has finished. The number of directories cached is limited. By default, directories are cached for repositories. This can be changes with the system property '' (if this is set to zero, no caching will take place; to cache the directories for each repository without eviction simply set this to a high enough value).
The usage of this pool has to be enabled by setting the system property `scm.workingCopyPoolStrategy` to 'sonia.scm.repository.work.SimpleCachingWorkingCopyPool'.
In general, this implementation should speed up modifications inside SCM-Manager performed by the editor plugin or the review plugin, but one has to take into account, that the space needed for repositories is multiplied. So you have to make sure, that there is enough space for clones of the repository.
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