improve repository caching

This commit is contained in:
Sebastian Sdorra
2011-11-07 13:17:46 +01:00
parent a53e2877f2
commit 8aa83e56f1
7 changed files with 306 additions and 16 deletions

View File

@@ -57,7 +57,7 @@ import java.io.IOException;
* @since 1.8 * @since 1.8
*/ */
@Singleton @Singleton
public class BlameViewerUtil extends CacheClearHook public class BlameViewerUtil extends PartCacheClearHook
{ {
/** Field description */ /** Field description */
@@ -104,8 +104,7 @@ public class BlameViewerUtil extends CacheClearHook
* @throws NotSupportedFeatuerException * @throws NotSupportedFeatuerException
* @throws RepositoryException * @throws RepositoryException
*/ */
public BlameResult getBlame(String repositoryId, String revision, public BlameResult getBlame(String repositoryId, String revision, String path)
String path)
throws RepositoryException, NotSupportedFeatuerException, IOException throws RepositoryException, NotSupportedFeatuerException, IOException
{ {
AssertUtil.assertIsNotEmpty(repositoryId); AssertUtil.assertIsNotEmpty(repositoryId);
@@ -177,7 +176,7 @@ public class BlameViewerUtil extends CacheClearHook
* @version Enter version here... * @version Enter version here...
* @author Enter your name here... * @author Enter your name here...
*/ */
private static class BlameViewerCacheKey private static class BlameViewerCacheKey implements RepositoryCacheKey
{ {
/** /**
@@ -269,6 +268,20 @@ public class BlameViewerUtil extends CacheClearHook
return hash; return hash;
} }
//~--- get methods --------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getRepositoryId()
{
return repositoryId;
}
//~--- fields ------------------------------------------------------------- //~--- fields -------------------------------------------------------------
/** Field description */ /** Field description */

View File

@@ -38,6 +38,7 @@ package sonia.scm.repository;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import sonia.scm.Filter;
import sonia.scm.cache.Cache; import sonia.scm.cache.Cache;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
@@ -63,8 +64,32 @@ public class CacheClearHook implements RepositoryHook
* Method description * Method description
* *
* @since 1.7 * @since 1.7
*
*/ */
public void clearCache() public void clearCache()
{
clearCache(null);
}
/**
* Method description
*
* @since 1.9
*
* @param filter
*/
public void clearCache(Filter filter)
{
if (filter != null)
{
if (logger.isDebugEnabled())
{
logger.debug("clear cache, with filter");
}
cache.removeAll(filter);
}
else
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -73,6 +98,7 @@ public class CacheClearHook implements RepositoryHook
cache.clear(); cache.clear();
} }
}
/** /**
* Method description * Method description
@@ -89,7 +115,9 @@ public class CacheClearHook implements RepositoryHook
event.getRepository().getName()); event.getRepository().getName());
} }
cache.clear(); Filter filter = createFilter(event);
clearCache(filter);
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
@@ -120,6 +148,20 @@ public class CacheClearHook implements RepositoryHook
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/**
* Method description
*
* @since 1.9
*
*
* @param event
* @return
*/
protected Filter<?> createFilter(RepositoryHookEvent event)
{
return null;
}
/** /**
* Method description * Method description
* *

View File

@@ -40,6 +40,7 @@ import com.google.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import sonia.scm.Filter;
import sonia.scm.NotSupportedFeatuerException; import sonia.scm.NotSupportedFeatuerException;
import sonia.scm.cache.Cache; import sonia.scm.cache.Cache;
import sonia.scm.cache.CacheManager; import sonia.scm.cache.CacheManager;
@@ -57,7 +58,7 @@ import java.util.Set;
* @author Sebastian Sdorra * @author Sebastian Sdorra
* @since 1.6 * @since 1.6
*/ */
public class ChangesetViewerUtil extends CacheClearHook public class ChangesetViewerUtil extends PartCacheClearHook
{ {
/** Field description */ /** Field description */
@@ -247,7 +248,7 @@ public class ChangesetViewerUtil extends CacheClearHook
* @version Enter version here..., 11/07/24 * @version Enter version here..., 11/07/24
* @author Enter your name here... * @author Enter your name here...
*/ */
private class ChangesetViewerCacheKey private class ChangesetViewerCacheKey implements RepositoryCacheKey
{ {
/** /**
@@ -340,6 +341,12 @@ public class ChangesetViewerUtil extends CacheClearHook
/** Field description */ /** Field description */
private int start; private int start;
@Override
public String getRepositoryId()
{
return repository;
}
} }

View File

@@ -0,0 +1,61 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Filter;
/**
*
* @author Sebastian Sdorra
* @since 1.9
*/
public class PartCacheClearHook extends CacheClearHook
{
/**
* Method description
*
*
* @param event
*
* @return
*/
@Override
protected Filter<?> createFilter(RepositoryHookEvent event)
{
return new RepositoryFilter(event);
}
}

View File

@@ -59,7 +59,7 @@ import java.util.List;
* @since 1.6 * @since 1.6
*/ */
@Singleton @Singleton
public class RepositoryBrowserUtil extends CacheClearHook public class RepositoryBrowserUtil extends PartCacheClearHook
{ {
/** Field description */ /** Field description */
@@ -205,7 +205,7 @@ public class RepositoryBrowserUtil extends CacheClearHook
* @version Enter version here..., 11/08/03 * @version Enter version here..., 11/08/03
* @author Enter your name here... * @author Enter your name here...
*/ */
private static class RepositoryBrowserCacheKey private static class RepositoryBrowserCacheKey implements RepositoryCacheKey
{ {
/** /**
@@ -297,6 +297,20 @@ public class RepositoryBrowserUtil extends CacheClearHook
return hash; return hash;
} }
//~--- get methods --------------------------------------------------------
/**
* Method description
*
*
* @return
*/
@Override
public String getRepositoryId()
{
return repositoryId;
}
//~--- fields ------------------------------------------------------------- //~--- fields -------------------------------------------------------------
/** Field description */ /** Field description */

View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
/**
*
* @author Sebastian Sdorra
* @since 1.9
*/
public interface RepositoryCacheKey
{
/**
* Method description
*
*
* @return
*/
public String getRepositoryId();
}

View File

@@ -0,0 +1,102 @@
/**
* Copyright (c) 2010, Sebastian Sdorra
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.Filter;
/**
*
* @author Sebastian Sdorra
* @since 1.9
*
*/
public class RepositoryFilter implements Filter<RepositoryCacheKey>
{
/**
* Constructs ...
*
*
* @param repository
*/
public RepositoryFilter(Repository repository)
{
this(repository.getId());
}
/**
* Constructs ...
*
*
* @param event
*/
public RepositoryFilter(RepositoryHookEvent event)
{
this(event.getRepository());
}
/**
* Constructs ...
*
*
* @param repositoryId
*/
public RepositoryFilter(String repositoryId)
{
this.repositoryId = repositoryId;
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param key
*
* @return
*/
@Override
public boolean accept(RepositoryCacheKey key)
{
return repositoryId.equals(key.getRepositoryId());
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private String repositoryId;
}