mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
EntityLookupCache uses separate cache-region wrappers for ID and value-based keys
- Avoids issues with Long-Long caching git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15663 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -318,7 +318,7 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
// Check if the value has a good key
|
||||
if (valueKey != null)
|
||||
{
|
||||
CacheRegionKey valueCacheKey = new CacheRegionKey(cacheRegion, valueKey);
|
||||
CacheRegionValueKey valueCacheKey = new CacheRegionValueKey(cacheRegion, valueKey);
|
||||
// The key is good, so we can cache the value
|
||||
cache.put(valueCacheKey, key);
|
||||
cache.put(
|
||||
@@ -361,7 +361,7 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
}
|
||||
|
||||
// Look in the cache
|
||||
CacheRegionKey valueCacheKey = new CacheRegionKey(cacheRegion, valueKey);
|
||||
CacheRegionValueKey valueCacheKey = new CacheRegionValueKey(cacheRegion, valueKey);
|
||||
K key = (K) cache.get(valueCacheKey);
|
||||
// Check if we have looked this up already
|
||||
if (key != null)
|
||||
@@ -436,7 +436,7 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
}
|
||||
|
||||
// Look in the cache
|
||||
CacheRegionKey valueCacheKey = new CacheRegionKey(cacheRegion, valueKey);
|
||||
CacheRegionValueKey valueCacheKey = new CacheRegionValueKey(cacheRegion, valueKey);
|
||||
K key = (K) cache.get(valueCacheKey);
|
||||
// Check if the value is already mapped to a key
|
||||
if (key != null && !key.equals(VALUE_NOT_FOUND))
|
||||
@@ -503,7 +503,7 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
}
|
||||
|
||||
// Cache the key and value
|
||||
CacheRegionKey valueCacheKey = new CacheRegionKey(cacheRegion, valueKey);
|
||||
CacheRegionValueKey valueCacheKey = new CacheRegionValueKey(cacheRegion, valueKey);
|
||||
cache.put(valueCacheKey, key);
|
||||
cache.put(
|
||||
new CacheRegionKey(cacheRegion, key),
|
||||
@@ -582,7 +582,7 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
{
|
||||
// Get the value key and remove it
|
||||
VK valueKey = entityLookup.getValueKey(value);
|
||||
CacheRegionKey valueCacheKey = new CacheRegionKey(cacheRegion, valueKey);
|
||||
CacheRegionValueKey valueCacheKey = new CacheRegionValueKey(cacheRegion, valueKey);
|
||||
cache.remove(valueCacheKey);
|
||||
}
|
||||
cache.remove(keyCacheKey);
|
||||
@@ -610,7 +610,7 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
return;
|
||||
}
|
||||
// Look in the cache
|
||||
CacheRegionKey valueCacheKey = new CacheRegionKey(cacheRegion, valueKey);
|
||||
CacheRegionValueKey valueCacheKey = new CacheRegionValueKey(cacheRegion, valueKey);
|
||||
K key = (K) cache.get(valueCacheKey);
|
||||
// Check if the value is already mapped to a key
|
||||
if (key != null && !key.equals(VALUE_NOT_FOUND))
|
||||
@@ -623,7 +623,8 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
|
||||
/**
|
||||
* Key-wrapper used to separate cache regions, allowing a single cache to be used for different
|
||||
* purposes.
|
||||
* purposes.<b/>
|
||||
* This class is distinct from the ID key so that ID-based lookups don't class with value-based lookups.
|
||||
*/
|
||||
private static class CacheRegionKey implements Serializable
|
||||
{
|
||||
@@ -663,4 +664,48 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Value-key-wrapper used to separate cache regions, allowing a single cache to be used for different
|
||||
* purposes.<b/>
|
||||
* This class is distinct from the region key so that ID-based lookups don't class with value-based lookups.
|
||||
*/
|
||||
private static class CacheRegionValueKey implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 5838308035326617927L;
|
||||
|
||||
private final String cacheRegion;
|
||||
private final Serializable cacheValueKey;
|
||||
private final int hashCode;
|
||||
private CacheRegionValueKey(String cacheRegion, Serializable cacheValueKey)
|
||||
{
|
||||
this.cacheRegion = cacheRegion;
|
||||
this.cacheValueKey = cacheValueKey;
|
||||
this.hashCode = cacheRegion.hashCode() + cacheValueKey.hashCode();
|
||||
}
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return cacheRegion + "." + cacheValueKey.toString();
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!(obj instanceof CacheRegionValueKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CacheRegionValueKey that = (CacheRegionValueKey) obj;
|
||||
return this.cacheRegion.equals(that.cacheRegion) && this.cacheValueKey.equals(that.cacheValueKey);
|
||||
}
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user