All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.portal.cache.ehcache.internal.EhcacheUnwrapUtil Maven / Gradle / Ivy

/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.portal.cache.ehcache.internal;

import com.liferay.portal.cache.PortalCacheWrapper;
import com.liferay.portal.kernel.cache.PortalCache;

import java.io.Serializable;

import net.sf.ehcache.Ehcache;

/**
 * @author Shuyang Zhou
 */
public class EhcacheUnwrapUtil {

	public static Ehcache getEhcache(PortalCache portalCache) {
		PortalCache wrappedPortalCache = getWrappedPortalCache(
			portalCache);

		if (wrappedPortalCache instanceof EhcacheWrapper) {
			EhcacheWrapper ehcacheWrapper = (EhcacheWrapper)wrappedPortalCache;

			return ehcacheWrapper.getEhcache();
		}

		throw new IllegalArgumentException(
			"Unable to locate Ehcache from " + portalCache);
	}

	public static  BaseEhcachePortalCache
		getWrappedPortalCache(PortalCache portalCache) {

		PortalCache currentPortalCache = portalCache;

		while (currentPortalCache instanceof PortalCacheWrapper) {
			PortalCacheWrapper portalCacheWrapper =
				(PortalCacheWrapper)currentPortalCache;

			currentPortalCache = portalCacheWrapper.getWrappedPortalCache();
		}

		return (BaseEhcachePortalCache)currentPortalCache;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy