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

org.thymeleaf.cache.AbstractCacheManager Maven / Gradle / Ivy

Go to download

Modern server-side Java template engine for both web and standalone environments

There is a newer version: 3.1.3.RELEASE
Show newest version
/*
 * =============================================================================
 *
 *   Copyright (c) 2011-2016, The THYMELEAF team (http://www.thymeleaf.org)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 * =============================================================================
 */
package org.thymeleaf.cache;

import java.util.Collections;
import java.util.List;

import org.thymeleaf.engine.TemplateModel;


/**
 * 

* Common abstract class for {@link ICacheManager} implementations, useful * for taking care of the lazy initialization of cache objects when their * corresponding getXCache() methods are called. *

*

* Note a class with this name existed since 2.0.0, but it was completely reimplemented * in Thymeleaf 3.0 *

* * * @author Daniel Fernández * * @since 3.0.0 * */ public abstract class AbstractCacheManager implements ICacheManager { private volatile ICache templateCache; private volatile boolean templateCacheInitialized = false; private volatile ICache expressionCache; private volatile boolean expressionCacheInitialized = false; protected AbstractCacheManager() { super(); } public final ICache getTemplateCache() { if (!this.templateCacheInitialized) { synchronized(this) { if (!this.templateCacheInitialized) { this.templateCache = initializeTemplateCache(); this.templateCacheInitialized = true; } } } return this.templateCache; } public final ICache getExpressionCache() { if (!this.expressionCacheInitialized) { synchronized(this) { if (!this.expressionCacheInitialized) { this.expressionCache = initializeExpressionCache(); this.expressionCacheInitialized = true; } } } return this.expressionCache; } public ICache getSpecificCache(final String name) { // No specific caches are used by default return null; } public List getAllSpecificCacheNames() { // No specific caches are used by default return Collections.emptyList(); } public void clearAllCaches() { final ICache templateCacheObj = getTemplateCache(); if (templateCacheObj != null) { templateCacheObj.clear(); } final ICache expressionCacheObj = getExpressionCache(); if (expressionCacheObj != null) { expressionCacheObj.clear(); } final List allSpecificCacheNamesObj = getAllSpecificCacheNames(); if (allSpecificCacheNamesObj != null) { for (final String specificCacheName : allSpecificCacheNamesObj) { final ICache specificCache = getSpecificCache(specificCacheName); if (specificCache != null) { specificCache.clear(); } } } } protected abstract ICache initializeTemplateCache(); protected abstract ICache initializeExpressionCache(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy