mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
simplify cache api
This commit is contained in:
@@ -36,6 +36,7 @@ package sonia.scm.api.rest.resources;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.github.legman.Subscribe;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -45,11 +46,13 @@ import org.codehaus.enunciate.modules.jersey.ExternallyManagedLifecycle;
|
||||
import sonia.scm.cache.Cache;
|
||||
import sonia.scm.cache.CacheManager;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.group.GroupEvent;
|
||||
import sonia.scm.group.GroupManager;
|
||||
import sonia.scm.search.SearchHandler;
|
||||
import sonia.scm.search.SearchResult;
|
||||
import sonia.scm.search.SearchResults;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserEvent;
|
||||
import sonia.scm.user.UserManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -59,8 +62,6 @@ import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import sonia.scm.group.GroupEvent;
|
||||
import sonia.scm.user.UserEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -94,14 +95,13 @@ public class SearchResource
|
||||
{
|
||||
|
||||
// create user searchhandler
|
||||
Cache<String, SearchResults> userCache =
|
||||
cacheManager.getCache(String.class, SearchResults.class, CACHE_USER);
|
||||
Cache<String, SearchResults> userCache = cacheManager.getCache(CACHE_USER);
|
||||
|
||||
this.userSearchHandler = new SearchHandler<User>(userCache, userManager);
|
||||
|
||||
// create group searchhandler
|
||||
Cache<String, SearchResults> groupCache =
|
||||
cacheManager.getCache(String.class, SearchResults.class, CACHE_GROUP);
|
||||
cacheManager.getCache(CACHE_GROUP);
|
||||
|
||||
this.groupSearchHandler = new SearchHandler<Group>(groupCache,
|
||||
groupManager);
|
||||
@@ -118,7 +118,8 @@ public class SearchResource
|
||||
@Subscribe
|
||||
public void onEvent(UserEvent event)
|
||||
{
|
||||
if ( event.getEventType().isPost() ){
|
||||
if (event.getEventType().isPost())
|
||||
{
|
||||
userSearchHandler.clearCache();
|
||||
}
|
||||
}
|
||||
@@ -132,7 +133,8 @@ public class SearchResource
|
||||
@Subscribe
|
||||
public void onEvent(GroupEvent event)
|
||||
{
|
||||
if ( event.getEventType().isPost() ){
|
||||
if (event.getEventType().isPost())
|
||||
{
|
||||
groupSearchHandler.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,8 +118,6 @@ public class GuavaCacheManager implements CacheManager
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @param name
|
||||
* @param <K>
|
||||
* @param <V>
|
||||
@@ -127,8 +125,7 @@ public class GuavaCacheManager implements CacheManager
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public synchronized <K, V> GuavaCache<K, V> getCache(Class<K> key,
|
||||
Class<V> value, String name)
|
||||
public synchronized <K, V> GuavaCache<K, V> getCache(String name)
|
||||
{
|
||||
logger.trace("try to retrieve cache {}", name);
|
||||
|
||||
|
||||
@@ -130,8 +130,7 @@ public class DefaultPluginManager implements PluginManager
|
||||
{
|
||||
this.context = context;
|
||||
this.configuration = configuration;
|
||||
this.cache = cacheManager.getCache(String.class, PluginCenter.class,
|
||||
CACHE_NAME);
|
||||
this.cache = cacheManager.getCache(CACHE_NAME);
|
||||
this.clientProvider = clientProvider;
|
||||
installedPlugins = new HashMap<String, Plugin>();
|
||||
|
||||
|
||||
@@ -106,8 +106,7 @@ public class AuthorizationCollector
|
||||
RepositoryDAO repositoryDAO, SecuritySystem securitySystem,
|
||||
PermissionResolver resolver)
|
||||
{
|
||||
this.cache = cacheManager.getCache(CacheKey.class, AuthorizationInfo.class,
|
||||
CACHE_NAME);
|
||||
this.cache = cacheManager.getCache(CACHE_NAME);
|
||||
this.repositoryDAO = repositoryDAO;
|
||||
this.securitySystem = securitySystem;
|
||||
this.resolver = resolver;
|
||||
@@ -524,15 +523,15 @@ public class AuthorizationCollector
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Cache<CacheKey, AuthorizationInfo> cache;
|
||||
/** authorization cache */
|
||||
private final Cache<CacheKey, AuthorizationInfo> cache;
|
||||
|
||||
/** Field description */
|
||||
private RepositoryDAO repositoryDAO;
|
||||
/** repository dao */
|
||||
private final RepositoryDAO repositoryDAO;
|
||||
|
||||
/** Field description */
|
||||
private PermissionResolver resolver;
|
||||
/** permission resolver */
|
||||
private final PermissionResolver resolver;
|
||||
|
||||
/** Field description */
|
||||
private SecuritySystem securitySystem;
|
||||
/** security system */
|
||||
private final SecuritySystem securitySystem;
|
||||
}
|
||||
|
||||
@@ -100,8 +100,7 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
|
||||
AssertUtil.assertIsNotNull(cacheManager);
|
||||
this.authenticationHandlers = sort(userManager, authenticationHandlerSet);
|
||||
this.encryptionHandler = encryptionHandler;
|
||||
this.cache = cacheManager.getCache(String.class,
|
||||
AuthenticationCacheValue.class, CACHE_NAME);
|
||||
this.cache = cacheManager.getCache(CACHE_NAME);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -368,12 +367,12 @@ public class ChainAuthenticatonManager extends AbstractAuthenticationManager
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private List<AuthenticationHandler> authenticationHandlers;
|
||||
/** authentication handlers */
|
||||
private final List<AuthenticationHandler> authenticationHandlers;
|
||||
|
||||
/** Field description */
|
||||
private Cache<String, AuthenticationCacheValue> cache;
|
||||
/** authentication cache */
|
||||
private final Cache<String, AuthenticationCacheValue> cache;
|
||||
|
||||
/** Field description */
|
||||
private EncryptionHandler encryptionHandler;
|
||||
/** encryption handler */
|
||||
private final EncryptionHandler encryptionHandler;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user