com.liferay.portal.kernel.cache.thread.local.ThreadLocalCacheManager Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.kernel.cache.thread.local;
import com.liferay.petra.lang.CentralizedThreadLocal;
import com.liferay.portal.kernel.transaction.NewTransactionLifecycleListener;
import com.liferay.portal.kernel.transaction.TransactionAttribute;
import com.liferay.portal.kernel.transaction.TransactionLifecycleListener;
import com.liferay.portal.kernel.transaction.TransactionStatus;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author Shuyang Zhou
*/
public class ThreadLocalCacheManager {
public static final TransactionLifecycleListener
TRANSACTION_LIFECYCLE_LISTENER = new NewTransactionLifecycleListener() {
@Override
protected void doCommitted(
TransactionAttribute transactionAttribute,
TransactionStatus transactionStatus) {
if (!transactionAttribute.isReadOnly()) {
enable(Lifecycle.REQUEST);
}
}
@Override
protected void doCreated(
TransactionAttribute transactionAttribute,
TransactionStatus transactionStatus) {
if (!transactionAttribute.isReadOnly()) {
disable(Lifecycle.REQUEST);
}
}
@Override
protected void doRollbacked(
TransactionAttribute transactionAttribute,
TransactionStatus transactionStatus, Throwable throwable) {
if (!transactionAttribute.isReadOnly()) {
enable(Lifecycle.REQUEST);
}
}
};
public static void clearAll(Lifecycle lifecycle) {
ThreadLocalCaches threadLocalCaches = _getThreadLocalCaches(lifecycle);
if (threadLocalCaches != null) {
Map