[exo-jcr-commits] exo-jcr SVN: r5256 - core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Dec 2 08:29:17 EST 2011
Author: nzamosenchuk
Date: 2011-12-02 08:29:16 -0500 (Fri, 02 Dec 2011)
New Revision: 5256
Modified:
core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/CacheHandler.java
Log:
EXOJCR-1663 : CacheHandler extended with prefix cache-key feture.
Modified: core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/CacheHandler.java
===================================================================
--- core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/CacheHandler.java 2011-12-02 09:43:18 UTC (rev 5255)
+++ core/trunk/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/CacheHandler.java 2011-12-02 13:29:16 UTC (rev 5256)
@@ -61,7 +61,7 @@
* Cache for Groups.
*/
protected final ExoCache<Serializable, Group> groupCache;
-
+
/**
* Constructor CacheHandler.
*
@@ -79,6 +79,8 @@
public void put(Serializable key, Object value, CacheType cacheType)
{
+ key = createInternalKey(key);
+
if (cacheType == CacheType.USER)
{
userCache.put(key, (User)value);
@@ -104,6 +106,8 @@
public Object get(Serializable key, CacheType cacheType)
{
Object obj = null;
+ key = createInternalKey(key);
+
if (cacheType == CacheType.USER)
{
obj = userCache.get(key);
@@ -134,16 +138,8 @@
public void remove(Serializable key, CacheType cacheType)
{
- if (cacheType == CacheType.USER)
+ if (cacheType == CacheType.MEMBERSHIP)
{
- userCache.remove(key);
- }
- else if (cacheType == CacheType.GROUP)
- {
- groupCache.remove(key);
- }
- else if (cacheType == CacheType.MEMBERSHIP)
- {
try
{
for (Membership m : membershipCache.getCachedObjects())
@@ -151,7 +147,7 @@
String mkey = getMembershipKey(m);
if (mkey.indexOf((String)key) >= 0)
{
- membershipCache.remove(mkey);
+ membershipCache.remove(createInternalKey(mkey));
}
}
}
@@ -159,28 +155,33 @@
{
}
}
- else if (cacheType == CacheType.MEMBERSHIPTYPE)
+ else
{
- membershipTypeCache.remove(key);
+ key = createInternalKey(key);
+
+ if (cacheType == CacheType.USER)
+ {
+ userCache.remove(key);
+ }
+ else if (cacheType == CacheType.GROUP)
+ {
+ groupCache.remove(key);
+ }
+ else if (cacheType == CacheType.MEMBERSHIPTYPE)
+ {
+ membershipTypeCache.remove(key);
+ }
+ else if (cacheType == CacheType.USER_PROFILE)
+ {
+ userProfileCache.remove(key);
+ }
}
- else if (cacheType == CacheType.USER_PROFILE)
- {
- userProfileCache.remove(key);
- }
}
public void move(Serializable oldKey, Serializable newKey, CacheType cacheType)
{
- if (cacheType == CacheType.USER)
+ if (cacheType == CacheType.MEMBERSHIP)
{
- userCache.put(newKey, userCache.remove(oldKey));
- }
- else if (cacheType == CacheType.GROUP)
- {
- groupCache.put(newKey, groupCache.remove(oldKey));
- }
- else if (cacheType == CacheType.MEMBERSHIP)
- {
try
{
Map<Serializable, Membership> wait4Adding = new HashMap<Serializable, Membership>();
@@ -190,24 +191,38 @@
String mkey = getMembershipKey(m);
if (mkey.indexOf((String)oldKey) >= 0)
{
- wait4Adding.put(mkey.replace((String)oldKey, (String)newKey), membershipCache.remove(mkey));
+ wait4Adding.put(createInternalKey(mkey.replace((String)oldKey, (String)newKey)),
+ membershipCache.remove(createInternalKey(mkey)));
}
}
-
membershipCache.putMap(wait4Adding);
}
catch (Exception e)
{
}
}
- else if (cacheType == CacheType.MEMBERSHIPTYPE)
+ else
{
- membershipTypeCache.put(newKey, membershipTypeCache.remove(oldKey));
+ oldKey = createInternalKey(oldKey);
+ newKey = createInternalKey(newKey);
+
+ if (cacheType == CacheType.USER)
+ {
+ userCache.put(newKey, userCache.remove(oldKey));
+ }
+ else if (cacheType == CacheType.GROUP)
+ {
+ groupCache.put(newKey, groupCache.remove(oldKey));
+ }
+ else if (cacheType == CacheType.MEMBERSHIPTYPE)
+ {
+ membershipTypeCache.put(newKey, membershipTypeCache.remove(oldKey));
+ }
+ else if (cacheType == CacheType.USER_PROFILE)
+ {
+ userProfileCache.put(newKey, userProfileCache.remove(oldKey));
+ }
}
- else if (cacheType == CacheType.USER_PROFILE)
- {
- userProfileCache.put(newKey, userProfileCache.remove(oldKey));
- }
}
public String getMembershipKey(Membership m)
@@ -230,8 +245,16 @@
return key.toString();
}
- public static enum CacheType
- {
+ public static enum CacheType {
USER, GROUP, MEMBERSHIP, MEMBERSHIPTYPE, USER_PROFILE
}
+
+ /**
+ * Provide a way of defining cache prefixes for descendant classes.
+ * This factory method is executed for each cache operation (put, get, remove)
+ */
+ protected Serializable createInternalKey(Serializable key)
+ {
+ return key;
+ }
}
More information about the exo-jcr-commits
mailing list