001
014
015 package com.liferay.portal.cache.mvcc;
016
017 import com.liferay.portal.cache.ehcache.LockBasedMVCCEhcachePortalCache;
018 import com.liferay.portal.kernel.cache.LowLevelCache;
019 import com.liferay.portal.kernel.cache.PortalCache;
020 import com.liferay.portal.kernel.cache.PortalCacheWrapper;
021 import com.liferay.portal.model.MVCCModel;
022 import com.liferay.portal.util.PropsValues;
023
024 import java.io.Serializable;
025
026
029 public class MVCCPortalCacheFactory {
030
031 public static <K extends Serializable>
032 PortalCache<K, ?> createMVCCEhcachePortalCache(
033 PortalCache<K, ?> portalCache) {
034
035 if (portalCache instanceof LowLevelCache) {
036 if (PropsValues.EHCACHE_CLUSTER_LINK_REPLICATION_ENABLED) {
037 return new MVCCPortalCache<K, MVCCModel>(
038 (LowLevelCache<K, MVCCModel>)portalCache);
039 }
040 else {
041 return new LockBasedMVCCEhcachePortalCache<K, MVCCModel>(
042 (LowLevelCache<K, MVCCModel>)portalCache);
043 }
044 }
045
046 PortalCache<K, ?> currentPortalCache = portalCache;
047
048 while (currentPortalCache instanceof PortalCacheWrapper) {
049 PortalCacheWrapper<K, MVCCModel> portalCacheWrapper =
050 (PortalCacheWrapper<K, MVCCModel>)currentPortalCache;
051
052 PortalCache<K, MVCCModel> nextPortalCache =
053 portalCacheWrapper.getWrappedPortalCache();
054
055 if (nextPortalCache instanceof LowLevelCache) {
056 if (PropsValues.EHCACHE_CLUSTER_LINK_REPLICATION_ENABLED) {
057 nextPortalCache = new MVCCPortalCache<K, MVCCModel>(
058 (LowLevelCache<K, MVCCModel>)nextPortalCache);
059 }
060 else {
061 nextPortalCache =
062 new LockBasedMVCCEhcachePortalCache<K, MVCCModel>(
063 (LowLevelCache<K, MVCCModel>)nextPortalCache);
064 }
065
066 portalCacheWrapper.setPortalCache(nextPortalCache);
067
068 break;
069 }
070 else {
071 currentPortalCache = nextPortalCache;
072 }
073 }
074
075 return portalCache;
076 }
077
078 }