databasecachemanager.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 576 行 · 第 1/2 页
JAVA
576 行
/** * $RCSfile: DatabaseCacheManager.java,v $ * $Revision: 1.20 $ * $Date: 2002/07/29 16:08:47 $ * * Copyright (C) 1999-2001 CoolServlets, Inc. All rights reserved. * * This software is the proprietary information of CoolServlets, Inc. * Use is subject to license terms. */package com.jivesoftware.forum.database;import com.jivesoftware.util.*;import com.jivesoftware.forum.*;/** * Central cache management of all caches used by Jive Forums. Cache sizes are * stored as the following Jive property values: <ul> * * <li> <tt>cache.userCache.size</tt> -- cache for User objects. * <li> <tt>cache.userCache.size</tt> -- cache mapping usernames to IDs. * <li> <tt>cache.groupCache.size</tt> -- cache for Group objects. * <li> <tt>cache.groupIDCache.size</tt> -- cache mapping group names to IDs. * <li> <tt>cache.groupMemberCache.size</tt> -- cache for storing the lists * of users in groups. * <li> <tt>cache.categoryCache.size</tt> -- cache for ForumCategory * objects. Because of the way most skins are implemented, it's * generally very important to make sure your category cache is * large enough to hold all category objects in cache at once. * <li> <tt>cache.forumCache.size</tt> -- cache for Forum objects. * Because most skins display a listing of all forums at once, it's * very important to make sure your forum cache is large enough to * hold all forum objects in cache at once. * <li> <tt>cache.forumIDCache.size</tt> -- cache mapping forum names to IDs. * <li> <tt>cache.threadCache.size</tt> -- cache for thread objects. * <li> <tt>cache.messageCache.size</tt> -- cache for message objects. * This cache should be relatively large compared to other caches * since the text of messages can eat a lot of memory. * <li> <tt>cache.attachmentCache.size</tt> -- cache for Attachment objects. * <li> <tt>cache.watchCache.size</tt> -- cache for Watch objects. * <li> <tt>cache.userPermsCache.size</tt> -- cache to store user permissions * on objects. * <li> <tt>cache.queryCache.size</tt> -- cache for results of ResultFilter * queries. * <li> <tt>cache.shortTermQueryCache.size</tt> -- short-term cache for * results of ResultFilter queries. * <li> <tt>cache.shortTermQueryCache.time</tt> -- the amount of time objects * should live in the short-term cache (in milleseconds). The default * value is 0, which means that the short-term cache is disabled. * If you wish to use short-term cache, a good value is 10000 * (10 seconds). * </ul> * * All values should be in bytes. Cache can also be globally enabled or disabled. * This value is stored as the <tt>cache.enabled</tt> Jive property. For sites * with extreme traffic (500K or more forum page views per day) a short-term * query cache can be enabled to that cache invalidations don't happen more than * once every X seconds (where X is the lifetime of objects in the short-term * cache). To enable the short-term query cache, set the * <tt>cache.shortTermQueryCache.time</tt> Jive property (expiration time in * milleseconds) -- for example, to 10000, so that query cache invalidations * only happen once every 10 seconds. * * @author Matt Tucker */public class DatabaseCacheManager { /** * A cache for User objects. */ public Cache userCache; /** * A cache for username to userID mappings. */ public Cache userIDCache; /** * A cache for Group objects. */ public Cache groupCache; /** * A cache for group name to groupID mappings. */ public Cache groupIDCache; /** * A cache for Category objects. */ public Cache categoryCache; /** * A cache for Forum objects. */ public Cache forumCache; /** * A cache for forum name to forumID mappings. */ public Cache forumIDCache; /** * A cache for ForumThread objects. */ public Cache threadCache; /** * A cache for ForumMessage objects. */ public Cache messageCache; /** * A cache for permissions. */ public Cache userPermsCache; /** * A cache for database query results generated by the use of ResultFilters. * Queries will either be for counts of objects, or lists of objects. */ public Cache queryCache; /** * A short-term cache for query results. */ public Cache shortTermQueryCache; /** * A cache for Watch objects. */ public Cache watchCache; /** * A cache for the list of users in groups and lists of the groups * that users belong to. */ public Cache groupMemberCache; /** * A cache of user message counts. This greatly helps for skins that * show the number of messages a user has posted next to each of their * messages. Each userManager implementation is responsible for actually * using this cache at its option. */ public Cache userMessageCountCache; /** * A cache for attachment objects. */ public Cache attachmentCache; private boolean cacheEnabled = true; private boolean shortTermQueryCacheEnabled = false; /** * Creates a new cache manager. */ public DatabaseCacheManager() { initCache(); } /** * Initializes all caches with the correct size and expiration time. */ private void initCache() { // This mehthod can be called externally -- for example, after switching // from local to clustered cache or vice versa. In that case, we only // need to clear out the query caches. if (queryCache != null) { queryCache.clear(); } if (shortTermQueryCache != null) { shortTermQueryCache.clear(); } long HOUR = JiveGlobals.HOUR; // See if cache is supposed to be enabled. String enabled = JiveGlobals.getJiveProperty("cache.enabled"); if (enabled != null) { try { cacheEnabled = Boolean.valueOf(enabled).booleanValue(); } catch (Exception e) { } } // Default cache sizes (small) int categoryCacheSize = 256*1024; // 1/4 MB int forumCacheSize = 512*1024; // 1/2 MB int forumIDCacheSize = 64*1024; // 1/16 MB int threadCacheSize = 512*1024; // 1/2 MB int messageCacheSize = 1152*1024; // 5/4 MB int userCacheSize = 512*1024; // 1/2 MB int userIDCacheSize = 128*1024; // 1/8 MB int userPermCacheSize = 256*1024; // 1/4 MB int groupCacheSize = 128*1024; // 1/8 MB int groupIDCacheSize = 128*1024; // 1/8 MB int watchCacheSize = 128*1024; // 1/8 MB int userMsgCountCacheSize = 64*1024; // 1/16 MB int queryCacheSize = 512*1024; // 1/2 MB int groupMemberCacheSize = 16*1024; int attachmentCacheSize = 64*1024; // 1/16 MB String cacheSize = null; cacheSize = JiveGlobals.getJiveProperty("cache.categoryCache.size"); if (cacheSize != null) { try { categoryCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.forumCache.size"); if (cacheSize != null) { try { forumCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.forumIDCache.size"); if (cacheSize != null) { try { forumIDCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.threadCache.size"); if (cacheSize != null) { try { threadCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.messageCache.size"); if (cacheSize != null) { try { messageCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.userCache.size"); if (cacheSize != null) { try { userCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.userIDCache.size"); if (cacheSize != null) { try { userIDCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.userPermsCache.size"); if (cacheSize != null) { try { userPermCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.groupCache.size"); if (cacheSize != null) { try { groupCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.groupIDCache.size"); if (cacheSize != null) { try { groupIDCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.watchCache.size"); if (cacheSize != null) { try { watchCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.userMsgCountCache.size"); if (cacheSize != null) { try { userMsgCountCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.queryCache.size"); if (cacheSize != null) { try { queryCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } /* cacheSize = JiveGlobals.getJiveProperty("cache.shortTermQueryCache.size"); if (cacheSize != null) { try { shortTermQueryCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheTime = JiveGlobals.getJiveProperty("cache.shortTermQueryCache.time"); if (cacheTime != null) { try { shortTermQueryCacheTime = Long.parseLong(cacheTime); } catch (Exception e) { } } */ cacheSize = JiveGlobals.getJiveProperty("cache.watchCache.size"); if (cacheSize != null) { try { watchCacheSize = Integer.parseInt(cacheSize); } catch (Exception e) { } } cacheSize = JiveGlobals.getJiveProperty("cache.groupMemberCache.size"); if (cacheSize != null) { try { groupMemberCacheSize = Integer.parseInt(cacheSize); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?