clear cache only on a post event

This commit is contained in:
Sebastian Sdorra
2012-08-27 08:00:16 +02:00
parent 2030a643d4
commit 585a2559ce
2 changed files with 66 additions and 17 deletions

View File

@@ -44,33 +44,75 @@ public enum HandlerEvent
/** /**
* After a new object is stored by a handler. * After a new object is stored by a handler.
*/ */
CREATE, CREATE(true),
/** /**
* After a object is modified by a handler. * After a object is modified by a handler.
*/ */
MODIFY, MODIFY(true),
/** /**
* After a object is removed by a handler. * After a object is removed by a handler.
*/ */
DELETE, DELETE(true),
/** /**
* Before a new object is stored by a handler. * Before a new object is stored by a handler.
* @since 1.16 * @since 1.16
*/ */
BEFORE_CREATE, BEFORE_CREATE(false),
/** /**
* Before a object is modified by a handler. * Before a object is modified by a handler.
* @since 1.16 * @since 1.16
*/ */
BEFORE_MODIFY, BEFORE_MODIFY(false),
/** /**
* Before a object is removed by a handler. * Before a object is removed by a handler.
* @since 1.16 * @since 1.16
*/ */
BEFORE_DELETE BEFORE_DELETE(false);
/**
* Constructs ...
*
*
* @param post
*/
private HandlerEvent(boolean post)
{
this.post = post;
}
//~--- get methods ----------------------------------------------------------
/**
* Returns true if the event is fired after the action is occurred.
*
*
* @return true if the event is fired after the action is occurred
* @since 1.21
*/
public boolean isPost()
{
return post;
}
/**
* Returns true if the event is fired before the action is occurred.
*
*
* @return true if the event is fired before the action is occurred
* @since 1.21
*/
public boolean isPre()
{
return !post;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private boolean post;
} }

View File

@@ -158,6 +158,9 @@ public class ScmRealm extends AuthorizingRealm
@Override @Override
public void onEvent(Repository repository, HandlerEvent event) public void onEvent(Repository repository, HandlerEvent event)
{ {
if (event.isPost())
{
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("clear cache, because repository {} has changed", logger.debug("clear cache, because repository {} has changed",
@@ -166,6 +169,7 @@ public class ScmRealm extends AuthorizingRealm
cache.clear(); cache.clear();
} }
}
/** /**
* Method description * Method description
@@ -176,6 +180,8 @@ public class ScmRealm extends AuthorizingRealm
*/ */
@Override @Override
public void onEvent(User user, HandlerEvent event) public void onEvent(User user, HandlerEvent event)
{
if (event.isPost())
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -186,6 +192,7 @@ public class ScmRealm extends AuthorizingRealm
cache.remove(user.getId()); cache.remove(user.getId());
} }
}
/** /**
* Method description * Method description