📄 simplecache.java
字号:
/******************************************************************************* * Copyright (C) 2002, 2003 * ingenieurbuero fuer innovative informationstechnik (iiit) * Dipl.-Ing. Joerg Beckmann, Dortmund, Germany * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * version $Id: SimpleCache.java,v 1.10 2003/04/13 20:28:01 joerg Exp $ ******************************************************************************/package de.iiit.access.server.plugins.cache;import de.iiit.access.common.cache.*;import de.iiit.access.server.*;import de.iiit.access.server.api.*;import de.iiit.xmlconfig.*;import de.iiit.cache.*;/** This cache can be loaded into the AccessServer as a plug-in to accelerate the * evaluation of expressions. * @version $Revision: 1.10 $ $Date: 2003/04/13 20:28:01 $ */public class SimpleCache implements CachePluginIf{ /** CVS Version Tag */ private static final String vcid = "$Id: SimpleCache.java,v 1.10 2003/04/13 20:28:01 joerg Exp $"; private static final String INVALIDATION_TIMEOUT = "InvalidationTimeout"; private static final String LRU_TIMEOUT = "LRUTimeout"; private static final String SLEEP_TIME = "SleepTime"; private int invalidationTimeout; private int lruTimeout; private int sleepTime; private boolean running = true; private boolean ignoreCase; UserRightsCache cache = null; /** Creates a new instance of SimpleCachePlugin */ public SimpleCache() { } /** Initializes the cache * @param config the configuration of the cache. Currently these parameters are * recognized: * <PRE> * InvalidationTimeout - after this period of time any elements in the cache will * be ignored to assure that changes in the rights will be recognized. * LRUTimeout - after this period of time an unused cache for a specific user will * be deleted. It does not make any sense to set this timeout * higher than the invalidation timeout. * SleepTime - The time to sleep between to runs of the cache cleaner. * </PRE> */ public void initialize(Configuration config) { invalidationTimeout = Integer.parseInt(config.getAttribute(INVALIDATION_TIMEOUT, "1800")) * 1000; // 30 Min lruTimeout = Integer.parseInt(config.getAttribute(LRU_TIMEOUT , "1800")) * 1000; // 30 Min sleepTime = Integer.parseInt(config.getAttribute(LRU_TIMEOUT , "10")) * 1000; // 10 Sec ignoreCase = AccessServer.getIgnoreCase(); } /** Starts the cleaner thread. This method is called by the AccessServer after the * initialization of all sub-moduls. */ public void start() { cache = new UserRightsCache(lruTimeout, invalidationTimeout, sleepTime); } /** Adds the result of one expression to the cache of the user. * @param user The name of the user * @param expression The expression * @param isAllowed The result of the expression */ public void addUserRight(String user, String expression, boolean isAllowed) { if (ignoreCase) { user = user.toLowerCase(); expression = expression.toLowerCase(); } cache.addUserRight(user, expression, isAllowed); } /** Retrieves the result of an expression from the cache. * @param user The name of the user for whom the result is needed. * @param expression The expression * @throws CacheFaultException if the result is not found in the cache * @return the result of the expression */ public boolean getUserRight(String user, String expression) throws CacheFaultException { if (ignoreCase) { user = user.toLowerCase(); expression = expression.toLowerCase(); } return cache.getUserRight(user, expression); } /** This method is called by the AccessServer when the background threads should * stop because of a shutdown of the AccessServer itself. */ public void shutdown() { if (cache != null) cache.shutdown(); } }/** * $Log: SimpleCache.java,v $ * Revision 1.10 2003/04/13 20:28:01 joerg * Package structure modified * * Revision 1.9 2003/04/13 20:16:41 joerg * Package structure modified * * Revision 1.8 2003/01/04 17:15:43 joerg * Zus鋞zliche Config-Option IgnoreCase * * Revision 1.7 2003/01/01 21:04:17 joerg * Copyright-Statement aktualisiert * * Revision 1.6 2002/12/24 21:04:33 joerg * Umbau der Paketstruktur * iiitLdapPlugin integriert * JavaDoc-Kommentare weiter vervollstaendigt. * * Revision 1.5 2002/12/23 11:29:35 joerg * start()- und shutdown()-Methode hinzugefuegt. * * Revision 1.4 2002/12/23 09:58:05 joerg * Klasse umbenannt in SimpleCachePlugin * * Revision 1.3 2002/12/22 20:45:12 joerg * shutdown()-Methode eingebaut * * Revision 1.2 2002/12/22 16:58:13 joerg * no message * * Revision 1.1 2002/12/19 15:24:23 joerg * Reparatur des CVS-Repositories * * Revision 1.3 2002/12/09 19:29:17 joerg * Versionsdaten in allen JavaDoc-Klassenbeschreibungen ergaenzt * * Revision 1.2 2002/12/09 16:32:26 joerg * JavaDoc Kommentare ergaenzt * * Revision 1.1 2002/11/19 20:23:22 joerg * Eingebautes Cache-Plugin fuer den AccessServer * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -