mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-08 11:52:57 +02:00
clear caches after received changes
This commit is contained in:
@@ -66,7 +66,7 @@ public final class BlameCommandBuilder
|
||||
{
|
||||
|
||||
/** name of the cache */
|
||||
private static final String CACHE_NAME = "sonia.scm.cache.blame";
|
||||
static final String CACHE_NAME = "sonia.scm.cache.blame";
|
||||
|
||||
/**
|
||||
* the logger for BlameCommandBuilder
|
||||
@@ -213,7 +213,7 @@ public final class BlameCommandBuilder
|
||||
* @version Enter version here..., 12/06/05
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class CacheKey implements Serializable
|
||||
static class CacheKey implements Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -270,6 +270,19 @@ public final class BlameCommandBuilder
|
||||
return Objects.hashCode(repositoryId, request);
|
||||
}
|
||||
|
||||
//~--- get methods --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getRepositoryId()
|
||||
{
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -65,7 +65,7 @@ public final class BrowseCommandBuilder
|
||||
{
|
||||
|
||||
/** Name of the cache */
|
||||
private static final String CACHE_NAME = "sonia.scm.cache.browse";
|
||||
static final String CACHE_NAME = "sonia.scm.cache.browse";
|
||||
|
||||
/**
|
||||
* the logger for BrowseCommandBuilder
|
||||
@@ -243,7 +243,7 @@ public final class BrowseCommandBuilder
|
||||
* @version Enter version here..., 12/06/05
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class CacheKey implements Serializable
|
||||
static class CacheKey implements Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -300,6 +300,19 @@ public final class BrowseCommandBuilder
|
||||
return Objects.hashCode(repositoryId, request);
|
||||
}
|
||||
|
||||
//~--- get methods --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getRepositoryId()
|
||||
{
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -105,7 +105,7 @@ public final class LogCommandBuilder
|
||||
{
|
||||
|
||||
/** name of the cache */
|
||||
private static final String CACHE_NAME = "sonia.scm.cache.log";
|
||||
static final String CACHE_NAME = "sonia.scm.cache.log";
|
||||
|
||||
/**
|
||||
* the logger for LogCommandBuilder
|
||||
@@ -423,7 +423,7 @@ public final class LogCommandBuilder
|
||||
* @version Enter version here..., 12/06/05
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class CacheKey implements Serializable
|
||||
static class CacheKey implements Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -495,6 +495,19 @@ public final class LogCommandBuilder
|
||||
return Objects.hashCode(repositoryId, changesetId, request);
|
||||
}
|
||||
|
||||
//~--- get methods --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getRepositoryId()
|
||||
{
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -44,11 +44,18 @@ import com.google.inject.Singleton;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.Filter;
|
||||
import sonia.scm.cache.Cache;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.repository.BlameResult;
|
||||
import sonia.scm.repository.BrowserResult;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.PermissionType;
|
||||
import sonia.scm.repository.PermissionUtil;
|
||||
import sonia.scm.repository.PostReceiveRepositoryHook;
|
||||
import sonia.scm.repository.PreProcessorUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryHookEvent;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.repository.RepositoryNotFoundException;
|
||||
import sonia.scm.repository.spi.RepositoryServiceProvider;
|
||||
@@ -124,6 +131,7 @@ public final class RepositoryServiceFactory
|
||||
this.securityContextProvider = securityContextProvider;
|
||||
this.resolvers = resolvers;
|
||||
this.preProcessorUtil = preProcessorUtil;
|
||||
repositoryManager.addHook(new CacheClearHook(cacheManager));
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -256,6 +264,111 @@ public final class RepositoryServiceFactory
|
||||
return service;
|
||||
}
|
||||
|
||||
//~--- inner classes --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* TODO find a more elegant way
|
||||
*
|
||||
*
|
||||
* @version Enter version here..., 12/06/16
|
||||
* @author Enter your name here...
|
||||
*/
|
||||
private static class CacheClearHook extends PostReceiveRepositoryHook
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param cacheManager
|
||||
*/
|
||||
public CacheClearHook(CacheManager cacheManager)
|
||||
{
|
||||
this.blameCache =
|
||||
cacheManager.getCache(BlameCommandBuilder.CacheKey.class,
|
||||
BlameResult.class,
|
||||
BlameCommandBuilder.CACHE_NAME);
|
||||
this.browseCache =
|
||||
cacheManager.getCache(BrowseCommandBuilder.CacheKey.class,
|
||||
BrowserResult.class,
|
||||
BrowseCommandBuilder.CACHE_NAME);
|
||||
this.logCache = cacheManager.getCache(LogCommandBuilder.CacheKey.class,
|
||||
ChangesetPagingResult.class, LogCommandBuilder.CACHE_NAME);
|
||||
}
|
||||
|
||||
//~--- methods ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void onEvent(RepositoryHookEvent event)
|
||||
{
|
||||
Repository repository = event.getRepository();
|
||||
|
||||
if (repository != null)
|
||||
{
|
||||
String id = repository.getId();
|
||||
|
||||
clearCaches(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param repositoryId
|
||||
*/
|
||||
private void clearCaches(final String repositoryId)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("clear caches for repository id {}", repositoryId);
|
||||
}
|
||||
|
||||
blameCache.removeAll(new Filter<BlameCommandBuilder.CacheKey>()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(BlameCommandBuilder.CacheKey item)
|
||||
{
|
||||
return repositoryId.equals(item.getRepositoryId());
|
||||
}
|
||||
});
|
||||
browseCache.removeAll(new Filter<BrowseCommandBuilder.CacheKey>()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(BrowseCommandBuilder.CacheKey item)
|
||||
{
|
||||
return repositoryId.equals(item.getRepositoryId());
|
||||
}
|
||||
});
|
||||
logCache.removeAll(new Filter<LogCommandBuilder.CacheKey>()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(LogCommandBuilder.CacheKey item)
|
||||
{
|
||||
return repositoryId.equals(item.getRepositoryId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//~--- fields -------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Cache<BlameCommandBuilder.CacheKey, BlameResult> blameCache;
|
||||
|
||||
/** Field description */
|
||||
private Cache<BrowseCommandBuilder.CacheKey, BrowserResult> browseCache;
|
||||
|
||||
/** Field description */
|
||||
private Cache<LogCommandBuilder.CacheKey, ChangesetPagingResult> logCache;
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
Reference in New Issue
Block a user