⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cache.jsp

📁 非常完整的Java开发的网络办公系统
💻 JSP
📖 第 1 页 / 共 2 页
字号:

<%
/**
 *	$RCSfile: cache.jsp,v $
 *	$Revision: 1.3.2.1 $
 *	$Date: 2001/05/10 02:06:34 $
 */
%>

<%@ page import="java.util.*,
				 java.text.*,
                 com.coolservlets.forum.*,
				 com.coolservlets.util.*,
				 com.coolservlets.forum.database.*,
				 com.coolservlets.forum.util.*,
				 com.coolservlets.forum.util.admin.*" %>

<jsp:useBean id="adminBean" scope="session"
 class="com.coolservlets.forum.util.admin.AdminBean"/>
 
<%	////////////////////////////////
	// Jive authorization check
	
	// check the bean for the existence of an authorization token.
	// Its existence proves the user is valid. If it's not found, redirect
	// to the login page
	Authorization authToken = adminBean.getAuthToken();
	if( authToken == null ) {
		response.sendRedirect( "/mainctrl/bbs/admin" );
		return;
	}
%>

<%	////////////////////
	// Security check
	
	// make sure the user is authorized to create forums::
	ForumFactory forumFactory = ForumFactory.getInstance(authToken);
	ForumPermissions permissions = forumFactory.getPermissions(authToken);
	boolean isSystemAdmin = permissions.get(ForumPermissions.SYSTEM_ADMIN);
	
	// redirect to error page if we're not a forum admin or a system admin
	if( !isSystemAdmin ) {
		request.setAttribute("message","没有权限创建论坛");
		response.sendRedirect("error.jsp");
		return;
	}
%>

<%	/////////////////
	// get parameters
	
	int cacheID = ParamUtils.getIntParameter(request,"cacheID",-1);
	boolean doClear = ParamUtils.getBooleanParameter(request,"doClear");
	boolean doEdit = ParamUtils.getBooleanParameter(request,"doEdit");
	boolean doSave = ParamUtils.getBooleanParameter(request,"doSave");
	int maxSize = ParamUtils.getIntParameter(request,"cacheMaxSize",-1);
	boolean cacheEnabled = ParamUtils.getBooleanParameter(request,"cacheEnabled");
	boolean doCache = ParamUtils.getBooleanParameter(request,"doCache");
	
	DbForumFactory dbForumFactory = null;
	try {
		dbForumFactory = (DbForumFactory)((ForumFactoryProxy)forumFactory).getUnderlyingForumFactory(); 
	} catch (Exception e) { }
	DbCacheManager cacheManager = dbForumFactory.getCacheManager();
	
	// clear the requested cache
	if( doClear ) {
		if( cacheID != -1 ) {
			cacheManager.clear(cacheID);
		}
	}
	
	if( doSave ) {
		if( cacheID != -1 ) {
			Cache cache = cacheManager.getCache(cacheID);
			cache.setMaxSize(maxSize*1024);
		}
	}
	
	// turn the cache on or off
	if( doCache ) {
		cacheManager.setCacheEnabled(cacheEnabled);
	}
	cacheEnabled = cacheManager.isCacheEnabled();
%>

<%!	
	Runtime runtime = Runtime.getRuntime();
%>

<html>
<head>
	<title></title>
	<link rel="stylesheet" href="style/global.css">
	<script language="JavaScript" type="text/javascript">
	function convert(src,dest) {
		if( dest.value == "" ) { return; }
		var unit = src.options[src.selectedIndex].value;
		if( unit == "K" ) {
			dest.value = dest.value * 1024;
		} else if( unit == "MB" ) {
			dest.value = dest.value / 1024;
		}
	}
	</script>
</head>

<body background="images/shadowBack.gif" bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<%	///////////////////////
	// pageTitleInfo variable (used by include/pageTitle.jsp)
	String[] pageTitleInfo = { "缓存" };
%>
<%	///////////////////
	// pageTitle include
%><%@ include file="include/pageTitle.jsp" %>

<p>

<b>缓存列表</b>
<ul>
	<%  DecimalFormat formatter = new DecimalFormat("#.00");
	%>
	
	<table bgcolor="#999999" cellpadding="0" cellspacing="0" border="0">
	<td>
	<table cellpadding="4" cellspacing="1" border="0" width="100%">
	<tr bgcolor="#eeeeee">
	<td class="forumCellHeader" align="center"><b>缓存类型</b></td>
	<td class="forumCellHeader" align="center"><b>大小</b></td>
	<td class="forumCellHeader" align="center"><b>对象</b></td>
	<td class="forumCellHeader" align="center"><b>效果</b></td>
	<td class="forumCellHeader" align="center">&nbsp;</td>
    </tr>
	<%
		Cache cache;
		double memUsed, totalMem, freeMem, hitPercent;
		long hits, misses;
	%>
		
	<tr bgcolor="#ffffff">
		<% cache = cacheManager.getCache(DbCacheManager.MESSAGE_CACHE); %>
		<td>帖子</td>
		<% 
			memUsed = (double)cache.getSize()/(1024*1024);
			totalMem = (double)cache.getMaxSize()/(1024*1024);
			freeMem = 100 - 100*memUsed/totalMem;
		%> 
		<td><%= formatter.format(totalMem) %> MB,
			<%= formatter.format(freeMem)%>%空闲
		</td>
		<td align=right>&nbsp;<%= cache.getNumElements() %>&nbsp;</td>
		<% 
			hits = cache.getCacheHits();
			misses = cache.getCacheMisses();
			if (hits + misses == 0) { hitPercent = 0.0; }
			else { hitPercent = 100*(double)hits/(hits+misses); }
		%>
		<td><%= formatter.format(hitPercent)%>% (<%= hits %>命中,<%= misses %>错失)</td> 
		<form action="cache.jsp">
		<input type="hidden" name="doEdit" value="true">
		<input type="hidden" name="cacheID" value="<%= DbCacheManager.MESSAGE_CACHE %>">
		</form>
		<form action="cache.jsp">
		<input type="hidden" name="doClear" value="true">
		<input type="hidden" name="cacheID" value="<%= DbCacheManager.MESSAGE_CACHE %>">
		<td><input type="submit" value="清理缓存"></td> 
		</form>
	</tr>
	<%	if( doEdit && cacheID==DbCacheManager.MESSAGE_CACHE ) { %>
	<tr bgcolor="#ffffff">
		<form action="cache.jsp">
		<input type="hidden" name="doSave" value="true">
		<input type="hidden" name="cacheID" value="<%= DbCacheManager.MESSAGE_CACHE %>">
		<td colspan="4">
			设置帖子大小:
			<input type="text" value="<%= cache.getMaxSize()/1024 %>" size="6"
			 name="cacheMaxSize">K 
			 <br>
			 1024 K = 1 MB, 2048 K = 2 MB, 3072 K = 3 MB
		</td>
		<td colspan="2" align="center"><input type="submit" value="保存"></td>
		</form>
	</tr>
	<%	} %>
	
	<tr bgcolor="#ffffff">
		<form action="cache.jsp">
		<input type="hidden" name="doClear" value="true">
		<input type="hidden" name="cacheID" value="<%= DbCacheManager.THREAD_CACHE %>">
		<% cache = cacheManager.getCache(DbCacheManager.THREAD_CACHE); %>
		<td>主题</td>
		<% 
			memUsed = (double)cache.getSize()/(1024*1024);
			totalMem = (double)cache.getMaxSize()/(1024*1024);
			freeMem = 100 - 100*memUsed/totalMem;
		%> 
		<td><%= formatter.format(totalMem) %> MB,
			<%= formatter.format(freeMem)%>%空闲
		</td>
		<td align=right>&nbsp;<%= cache.getNumElements() %>&nbsp;</td>
		<% 
			hits = cache.getCacheHits();
			misses = cache.getCacheMisses();
			if (hits + misses == 0) { hitPercent = 0.0; }
			else { hitPercent = 100*(double)hits/(hits+misses); }
		%>
		<td><%= formatter.format(hitPercent)%>% (<%= hits %>命中,<%= misses %>错失)</td> 
		<form action="cache.jsp">
		<input type="hidden" name="doEdit" value="true">
		<input type="hidden" name="cacheID" value="<%= DbCacheManager.THREAD_CACHE %>">
		</form>
		<form action="cache.jsp">
		<input type="hidden" name="doClear" value="true">
		<input type="hidden" name="cacheID" value="<%= DbCacheManager.THREAD_CACHE %>">
		<td><input type="submit" value="清理缓存"></td> 
		</form>
	</tr>
	<%	if( doEdit && cacheID==DbCacheManager.THREAD_CACHE ) { %>
	<tr bgcolor="#ffffff">
		<form action="cache.jsp">
		<input type="hidden" name="doSave" value="true">
		<input type="hidden" name="cacheID" value="<%= DbCacheManager.THREAD_CACHE %>">
		<td colspan="4">
			设置帖子大小:
			<input type="text" value="<%= cache.getMaxSize()/1024 %>" size="6"
			 name="cacheMaxSize">K 
			 <br>
			 1024 K = 1 MB, 2048 K = 2 MB, 3072 K = 3 MB
		</td>
		<td colspan="2" align="center"><input type="submit" value="保存"></td>
		</form>
	</tr>
	<%	} %>
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -