<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %> <%@ page import="com.opencms.flex.util.*,com.opencms.flex.cache.*,com.opencms.flex.*,com.opencms.core.*" %> <%@ page import="java.util.*" %> Flex Cache Administration

Flex Cache Administration

<% int sizeEntries = 0; int sizeKeys = 0; CmsFlexCache cache = null; com.opencms.file.CmsObject cms = null; int maxCacheByteSize = 0; int avgCacheByteSize = 0; int currentCacheByteSize = 0; int currentCacheObjectCount = 0; CmsFlexLruCache entryLruCache = null; String label_1 = "Clear entries only"; String label_2 = "Clear cache keys and entries completely"; String label_5 = "Clear only online entries"; String label_6 = "Clear only online keys and entries"; String label_7 = "Clear only offline entries"; String label_8 = "Clear only offline keys and entries"; String label_9 = "Purge JSP repository"; String label_3 = "Show cached resources with keys"; String label_4 = "Show cached resources with keys and entries"; String label_10 = "Reload this page"; out = pageContext.getOut(); if (request instanceof CmsFlexRequest) { // out.write("

CmsFlexRequest found!

"); CmsFlexRequest req = (CmsFlexRequest)request; cache = req.getCmsCache(); cms = req.getCmsObject(); } else { out.write("

NO CmsFlexRequest!

"); } String action = request.getParameter("action"); // out.write("Request action is: " + action); if (action != null) { if (label_1.equals(action)) { // cache.clearEntries(cms); A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ENTRIES)))); } else if (label_2.equals(action)) { // cache.clear(cms); A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ALL)))); } else if (label_6.equals(action)) { // cache.clearOnline(cms); A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ONLINE_ALL)))); } else if (label_5.equals(action)) { // cache.clearOnlineEntries(cms); A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ONLINE_ENTRIES)))); } else if (label_8.equals(action)) { // cache.clearOffline(cms); A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_OFFLINE_ALL)))); } else if (label_7.equals(action)) { // cache.clearOfflineEntries(cms); A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_OFFLINE_ENTRIES)))); } else if (label_9.equals(action)) { // cache.purgeJspRepository(cms); // cache.clear(cms); A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_PURGE_JSP_REPOSITORY, new HashMap(0), true)); A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ENTRIES)))); } } if (cache != null) { sizeEntries = cache.size(); sizeKeys = cache.keySize(); entryLruCache = cache.getEntryLruCache(); if (entryLruCache!=null) { maxCacheByteSize = entryLruCache.getMaxCacheCosts(); avgCacheByteSize = entryLruCache.getAvgCacheCosts(); currentCacheByteSize = entryLruCache.getObjectCosts(); currentCacheObjectCount = entryLruCache.size(); } } %>

Entries in Flex Cache: <%=sizeEntries%>
Keys in Flex Cache: <%=sizeKeys%>
Max. size of all entries: <%=maxCacheByteSize%> bytes
Avg. size of all entries: <%=avgCacheByteSize%> bytes
Cur. size of all entries: <%=currentCacheByteSize%> bytes


<% if (cache.cacheOffline()) { %>


<% } %>

<% if ((action != null) && (cache != null)) { if (label_3.equals(action) || label_4.equals(action)) { boolean showall = false; if (label_4.equals(action)) { showall = true; out.write("

Cached resources with keys and entries:

"); } else { out.write("

Cached resources with keys:

"); } Set set = cache.getCachedResources(cms); if (cache.cacheOffline()) { Set online = new TreeSet(); Set offline = new TreeSet(); Iterator i = set.iterator(); while(i.hasNext()) { String resource = (String)i.next(); if (resource.endsWith(cache.C_CACHE_OFFLINESUFFIX)) { offline.add(resource); } else { online.add(resource); } } out.write("

Online resources:

"); i = online.iterator(); while(i.hasNext()) { String resource = (String)i.next(); out.write("Resource: " + resource + "   Key: " + cache.getCachedKey(resource, cms) + "
"); if (showall) { Set variations = cache.getCachedVariations(resource, cms); if (variations.size() > 0) { Iterator s = variations.iterator(); while (s.hasNext()) { String v = (String)s.next(); out.write("        Entry: " + v + "
"); } } } } if (online.size() == 0) out.write("There are no cached online resources!"); out.write("

Offline resources:

"); i = offline.iterator(); while(i.hasNext()) { String resource = (String)i.next(); out.write("Resource: " + resource + "   Key: " + cache.getCachedKey(resource, cms) + "
"); if (showall) { Set variations = cache.getCachedVariations(resource, cms); if (variations.size() > 0) { Iterator s = variations.iterator(); while (s.hasNext()) { String v = (String)s.next(); out.write("        Entry: " + v + "
"); } } } } if (offline.size() == 0) out.write("There are no cached offline resources!"); } else { Iterator i = set.iterator(); while(i.hasNext()) { String resource = (String)i.next(); out.write("Resource: " + resource + "   Key: " + cache.getCachedKey(resource, cms) + "
"); if (showall) { Set variations = cache.getCachedVariations(resource, cms); if (variations.size() > 0) { Iterator s = variations.iterator(); while (s.hasNext()) { String v = (String)s.next(); out.write("        Entry: " + v + "
"); } } } } if (set.size() == 0) out.write("The cache is currently empty!"); } } } %>