Skip to content
Snippets Groups Projects
Commit c51a87e5 authored by srosse's avatar srosse
Browse files

OO-948: use "putIfAbsent" instead of doInSync for the calendar's cache

parent 95abc52e
No related branches found
No related tags found
No related merge requests found
...@@ -164,25 +164,20 @@ public class ICalFileCalendarManager extends BasicManager implements CalendarMan ...@@ -164,25 +164,20 @@ public class ICalFileCalendarManager extends BasicManager implements CalendarMan
String key = getKeyFor(type, calendarID); String key = getKeyFor(type, calendarID);
Kalendar cal = calendarCache.get(key); Kalendar cal = calendarCache.get(key);
if(cal == null) { if(cal == null) {
//o_clusterOK by:cg cal = getCalendarFromCache(type, calendarID);
OLATResourceable calOres = OresHelper.createOLATResourceableType(getKeyFor(type,calendarID));
cal = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync( calOres, new SyncerCallback<Kalendar>() {
public Kalendar execute() {
return getCalendarFromCache(type, calendarID);
}
});
} }
return cal; return cal;
} }
private Kalendar getCalendarFromCache(final String callType, final String callCalendarID) { private Kalendar getCalendarFromCache(final String callType, final String callCalendarID) {
String calKey = getKeyFor(callType,callCalendarID); String calKey = getKeyFor(callType,callCalendarID);
OLATResourceable calOres = OresHelper.createOLATResourceableType(calKey);
CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(calOres);
Kalendar cal = calendarCache.get(calKey); Kalendar cal = calendarCache.get(calKey);
if (cal == null) { if (cal == null) {
cal = loadOrCreateCalendar(callType, callCalendarID); cal = loadOrCreateCalendar(callType, callCalendarID);
calendarCache.put(calKey, cal); Kalendar cacheCal = calendarCache.putIfAbsent(calKey, cal);
if(cacheCal != null) {
cal = cacheCal;
}
} }
return cal; return cal;
} }
......
...@@ -89,6 +89,8 @@ public interface CacheWrapper<U, V extends Serializable> { ...@@ -89,6 +89,8 @@ public interface CacheWrapper<U, V extends Serializable> {
*/ */
public V put(U key, V value); public V put(U key, V value);
public V putIfAbsent(U key, V value);
/** /**
* In the case of distributed cache, the list can be partial and * In the case of distributed cache, the list can be partial and
* you must carefully setup your cache. * you must carefully setup your cache.
......
...@@ -102,4 +102,11 @@ public class InfinispanCacheWrapper<U,V extends Serializable> implements CacheWr ...@@ -102,4 +102,11 @@ public class InfinispanCacheWrapper<U,V extends Serializable> implements CacheWr
V oldOne = cache.put(key, value); V oldOne = cache.put(key, value);
return oldOne; return oldOne;
} }
@Override
public V putIfAbsent(U key, V value) {
return cache.putIfAbsent(key, value);
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment