📄 cmsflexcache.java
字号:
LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_RESOURCE_NOT_CACHEABLE_0));
}
return false;
}
}
/**
* Adds a key with a new, empty variation map to the cache.<p>
*
* @param key the key to add to the cache.
*/
void putKey(CmsFlexCacheKey key) {
if (!isEnabled()) {
return;
}
Object o = m_keyCache.get(key.getResource());
if (o == null) {
// No variation map for this resource yet, so create one
CmsFlexCacheVariation variationMap = new CmsFlexCacheVariation(key);
m_keyCache.put(key.getResource(), variationMap);
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_ADD_KEY_1, key.getResource()));
}
}
// If != null the key is already in the cache, so we just do nothing
}
/**
* Removes an entry from the cache.<p>
*
* @param key the key which describes the entry to remove from the cache
*/
void remove(CmsFlexCacheKey key) {
if (!isEnabled()) {
return;
}
Object o = m_keyCache.get(key.getResource());
if (o != null) {
//Object old = ((HashMap)o).remove(key.Variation);
Object old = ((HashMap)o).get(key.getVariation());
if (old != null) {
getEntryLruCache().remove((I_CmsLruCacheObject)old);
}
}
}
/**
* Emptys the cache completely.<p>
*/
private synchronized void clear() {
if (!isEnabled()) {
return;
}
m_keyCache.clear();
m_size = 0;
m_variationCache.clear();
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_CLEAR_0));
}
}
/**
* Internal method to perform cache clearance.<p>
*
* It clears "one half" of the cache, i.e. either
* the online or the offline parts.
* A parameter is used to indicate if only
* the entries or keys and entries are to be cleared.<p>
*
* @param suffix used to distinguish between "[Online]" and "[Offline]" entries
* @param entriesOnly if <code>true</code>, only entries will be cleared, otherwise
* the entries and the keys will be cleared
*/
private synchronized void clearAccordingToSuffix(String suffix, boolean entriesOnly) {
Set keys = new HashSet(m_keyCache.keySet());
Iterator i = keys.iterator();
while (i.hasNext()) {
String s = (String)i.next();
if (s.endsWith(suffix)) {
CmsFlexCacheVariation v = (CmsFlexCacheVariation)m_keyCache.get(s);
if (entriesOnly) {
// Clear only entry
m_size -= v.m_map.size();
Iterator allEntries = v.m_map.values().iterator();
while (allEntries.hasNext()) {
I_CmsLruCacheObject nextObject = (I_CmsLruCacheObject)allEntries.next();
allEntries.remove();
m_variationCache.remove(nextObject);
}
v.m_map = new Hashtable(INITIAL_CAPACITY_VARIATIONS);
} else {
// Clear key and entry
m_size -= v.m_map.size();
Iterator allEntries = v.m_map.values().iterator();
while (allEntries.hasNext()) {
I_CmsLruCacheObject nextObject = (I_CmsLruCacheObject)allEntries.next();
allEntries.remove();
m_variationCache.remove(nextObject);
}
v.m_map = null;
v.m_key = null;
m_keyCache.remove(s);
}
}
}
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(
Messages.LOG_FLEXCACHE_CLEAR_HALF_2,
suffix,
new Boolean(entriesOnly)));
}
}
/**
* Clears all entries in the cache, online or offline.<p>
*
* The keys are not cleared.<p>
*
* Only users with administrator permissions are allowed
* to perform this operation.<p>
*/
private synchronized void clearEntries() {
if (!isEnabled()) {
return;
}
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_CLEAR_ALL_0));
}
// create new set to avoid ConcurrentModificationExceptions
Set cacheKeys = new HashSet(m_keyCache.keySet());
Iterator i = cacheKeys.iterator();
while (i.hasNext()) {
CmsFlexCacheVariation v = (CmsFlexCacheVariation)m_keyCache.get(i.next());
Iterator allEntries = v.m_map.values().iterator();
while (allEntries.hasNext()) {
I_CmsLruCacheObject nextObject = (I_CmsLruCacheObject)allEntries.next();
allEntries.remove();
m_variationCache.remove(nextObject);
}
v.m_map = new Hashtable(INITIAL_CAPACITY_VARIATIONS);
}
m_size = 0;
}
/**
* Clears all entries and all keys from offline projects in the cache.<p>
*
* Cached resources from the online project are not touched.<p>
*
* Only users with administrator permissions are allowed
* to perform this operation.<p>
*/
private void clearOffline() {
if (!isEnabled()) {
return;
}
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_CLEAR_KEYS_AND_ENTRIES_0));
}
clearAccordingToSuffix(CACHE_OFFLINESUFFIX, false);
}
/**
* Clears all entries from offline projects in the cache.<p>
*
* The keys from the offline projects are not cleared.
* Cached resources from the online project are not touched.<p>
*
* Only users with administrator permissions are allowed
* to perform this operation.<p>
*/
private void clearOfflineEntries() {
if (!isEnabled()) {
return;
}
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_CLEAR_OFFLINE_ENTRIES_0));
}
clearAccordingToSuffix(CACHE_OFFLINESUFFIX, true);
}
/**
* Clears all entries and all keys from the online project in the cache.<p>
*
* Cached resources from the offline projects are not touched.<p>
*
* Only users with administrator permissions are allowed
* to perform this operation.<p>
*/
private void clearOnline() {
if (!isEnabled()) {
return;
}
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_CLEAR_ONLINE_KEYS_AND_ENTRIES_0));
}
clearAccordingToSuffix(CACHE_ONLINESUFFIX, false);
}
/**
* Clears all entries from the online project in the cache.<p>
*
* The keys from the online project are not cleared.
* Cached resources from the offline projects are not touched.<p>
*
* Only users with administrator permissions are allowed
* to perform this operation.<p>
*/
private void clearOnlineEntries() {
if (!isEnabled()) {
return;
}
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_CLEAR_ONLINE_ENTRIES_0));
}
clearAccordingToSuffix(CACHE_ONLINESUFFIX, true);
}
/**
* This method purges the JSP repository dirs,
* i.e. it deletes all JSP files that OpenCms has written to the
* real FS.<p>
*
* Obviously this method must be used with caution.
* Purpose of this method is to allow
* a complete purge of all JSP pages on a machine after
* a major update of JSP templates was made.<p>
*/
private synchronized void purgeJspRepository() {
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_WILL_PURGE_JSP_REPOSITORY_0));
}
File d;
d = new File(org.opencms.loader.CmsJspLoader.getJspRepository() + REPOSITORY_ONLINE + File.separator);
CmsFileUtil.purgeDirectory(d);
d = new File(org.opencms.loader.CmsJspLoader.getJspRepository() + REPOSITORY_OFFLINE + File.separator);
CmsFileUtil.purgeDirectory(d);
clear();
if (LOG.isInfoEnabled()) {
LOG.info(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_PURGED_JSP_REPOSITORY_0));
}
}
/**
* Save a value to the cache.<p>
*
* @param key the key under shich the value is saved
* @param theCacheEntry the entry to cache
*/
private void put(CmsFlexCacheKey key, CmsFlexCacheEntry theCacheEntry) {
Object o = m_keyCache.get(key.getResource());
if (key.getTimeout() > 0) {
theCacheEntry.setDateExpiresToNextTimeout(key.getTimeout());
}
if (o != null) {
// We already have a variation map for this resource
Map m = ((CmsFlexCacheVariation)o).m_map;
boolean wasAdded = true;
if (!m.containsKey(key.getVariation())) {
wasAdded = m_variationCache.add(theCacheEntry);
} else {
wasAdded = m_variationCache.touch(theCacheEntry);
}
if (wasAdded) {
theCacheEntry.setVariationData(key.getVariation(), m);
m.put(key.getVariation(), theCacheEntry);
}
} else {
// No variation map for this resource yet, so create one
CmsFlexCacheVariation list = new CmsFlexCacheVariation(key);
boolean wasAdded = m_variationCache.add(theCacheEntry);
if (wasAdded) {
theCacheEntry.setVariationData(key.getVariation(), list.m_map);
list.m_map.put(key.getVariation(), theCacheEntry);
m_keyCache.put(key.getResource(), list);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_FLEXCACHE_ADDED_ENTRY_FOR_RESOURCE_WITH_VARIATION_3,
new Integer(m_size),
key.getResource(),
key.getVariation()));
LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_ADDED_ENTRY_1, theCacheEntry.toString()));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -