Return-Path: Delivered-To: apmail-ibatis-dev-archive@www.apache.org Received: (qmail 29150 invoked from network); 20 Oct 2005 00:07:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Oct 2005 00:07:09 -0000 Received: (qmail 9323 invoked by uid 500); 20 Oct 2005 00:07:08 -0000 Delivered-To: apmail-ibatis-dev-archive@ibatis.apache.org Received: (qmail 9295 invoked by uid 500); 20 Oct 2005 00:07:08 -0000 Mailing-List: contact dev-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ibatis.apache.org Delivered-To: mailing list dev@ibatis.apache.org Received: (qmail 9270 invoked by uid 500); 20 Oct 2005 00:07:07 -0000 Delivered-To: apmail-incubator-ibatis-dev@incubator.apache.org Received: (qmail 9262 invoked by uid 99); 20 Oct 2005 00:07:07 -0000 X-ASF-Spam-Status: No, hits=1.3 required=10.0 tests=SPF_FAIL X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2005 17:07:06 -0700 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 2DE6C237 for ; Thu, 20 Oct 2005 02:06:45 +0200 (CEST) Message-ID: <903316097.1129766805185.JavaMail.jira@ajax.apache.org> Date: Thu, 20 Oct 2005 02:06:45 +0200 (CEST) From: "michael campbell (JIRA)" To: ibatis-dev@incubator.apache.org Subject: [jira] Created: (IBATIS-204) Cache layer does no logging of puts, gets, flushes, or removals. Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Cache layer does no logging of puts, gets, flushes, or removals. ---------------------------------------------------------------- Key: IBATIS-204 URL: http://issues.apache.org/jira/browse/IBATIS-204 Project: iBatis for Java Type: Improvement Components: SQL Maps Versions: 2.0.8, 2.0.9, 2.1.0, 2.0.9b, 2.1.5, 2.2.0, 2.2.5 Environment: All Reporter: michael campbell Priority: Minor The cache layer has no logging. Following is the code change I made (all cache mechanisms EXCEPT os-cache) to the cache code which suits my purposes. I tried to stay within the spirit of the existing logging, mimicing the output formats, etc. Released to the public domain. =======================/* * Copyright 2004 Clinton Begin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.ibatis.sqlmap.engine.cache.fifo; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; import com.ibatis.common.logging.Log; import com.ibatis.common.logging.LogFactory; import com.ibatis.sqlmap.engine.cache.CacheController; import com.ibatis.sqlmap.engine.cache.CacheModel; /** * FIFO (first in, first out) cache controller implementation */ public class FifoCacheController implements CacheController { private static Log _log = LogFactory.getLog(FifoCacheController.class); private Map cache; private int cacheSize; private List keyList; /** * Default constructor */ public FifoCacheController() { this.cacheSize = 100; this.cache = Collections.synchronizedMap(new HashMap()); this.keyList = Collections.synchronizedList(new LinkedList()); } /** * Configures the cache * * @param props * Optionally can contain properties [reference-type=WEAK|SOFT|STRONG] */ public void configure(Properties props) { String size = props.getProperty("cache-size"); if (size == null) { size = props.getProperty("size"); } if (size != null) { cacheSize = Integer.parseInt(size); } } /** * Flushes the cache. * * @param cacheModel * The cache model */ public void flush(CacheModel cacheModel) { if (_log.isDebugEnabled()) { _log.debug("{cache-FIFO} Flush"); } cache.clear(); keyList.clear(); } /** * Get an object out of the cache. * * @param cacheModel * The cache model * @param key * The key of the object to be returned * @return The cached object (or null) */ public Object getObject(CacheModel cacheModel, Object key) { Object value = cache.get(key); if (_log.isDebugEnabled()) { _log.debug("{cache-FIFO} GetObject-[" + key + "]-[" + value + "]"); } return value; } /** * Add an object to the cache * * @param cacheModel * The cacheModel * @param key * The key of the object to be cached * @param value * The object to be cached */ public void putObject(CacheModel cacheModel, Object key, Object value) { if (_log.isDebugEnabled()) { _log.debug("{cache-FIFO} PutObject-[" + key + "]-[" + value + "]"); } cache.put(key, value); keyList.add(key); if (keyList.size() > cacheSize) { try { Object oldestKey = keyList.remove(0); cache.remove(oldestKey); } catch (IndexOutOfBoundsException e) { // ignore } } } public Object removeObject(CacheModel cacheModel, Object key) { keyList.remove(key); Object value = cache.remove(key); if (_log.isDebugEnabled()) { _log.debug("{cache-FIFO} RemoveObject-[" + key + "]-[" + value + "]"); } return value; } } ============================================ /* * Copyright 2004 Clinton Begin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.ibatis.sqlmap.engine.cache.lru; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; import com.ibatis.common.logging.Log; import com.ibatis.common.logging.LogFactory; import com.ibatis.sqlmap.engine.cache.CacheController; import com.ibatis.sqlmap.engine.cache.CacheModel; /** * LRU (least recently used) cache controller implementation */ public class LruCacheController implements CacheController { private static Log _log = LogFactory.getLog(LruCacheController.class); private Map cache; private int cacheSize; private List keyList; /** * Default constructor */ public LruCacheController() { this.cacheSize = 100; this.cache = Collections.synchronizedMap(new HashMap()); this.keyList = Collections.synchronizedList(new LinkedList()); } /** * Configures the cache * * @param props * Optionally can contain properties [reference-type=WEAK|SOFT|STRONG] */ public void configure(Properties props) { String size = props.getProperty("cache-size"); if (size == null) { size = props.getProperty("size"); } if (size != null) { cacheSize = Integer.parseInt(size); } } /** * Flushes the cache. * * @param cacheModel * The cache model */ public void flush(CacheModel cacheModel) { if (_log.isDebugEnabled()) { _log.debug("{cache-LRU} Flush"); } cache.clear(); keyList.clear(); } /** * Get an object out of the cache. * * @param cacheModel * The cache model * @param key * The key of the object to be returned * @return The cached object (or null) */ public Object getObject(CacheModel cacheModel, Object key) { Object result = cache.get(key); if (_log.isDebugEnabled()) { _log.debug("{cache-LRU} GetObject-[" + key + "]-[" + result + "]"); } keyList.remove(key); if (result != null) { keyList.add(key); } return result; } /** * Add an object to the cache * * @param cacheModel * The cacheModel * @param key * The key of the object to be cached * @param value * The object to be cached */ public void putObject(CacheModel cacheModel, Object key, Object value) { if (_log.isDebugEnabled()) { _log.debug("{cache-LRU} PutObject-[" + key + "]-[" + value + "]"); } cache.put(key, value); keyList.add(key); if (keyList.size() > cacheSize) { try { Object oldestKey = keyList.remove(0); cache.remove(oldestKey); } catch (IndexOutOfBoundsException e) { // ignore } } } public Object removeObject(CacheModel cacheModel, Object key) { keyList.remove(key); Object value = cache.remove(key); if (_log.isDebugEnabled()) { _log.debug("{cache-LRU} RemoveObject-[" + key + "]-[" + value + "]"); } return value; } } =============================================== /* * Copyright 2004 Clinton Begin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.ibatis.sqlmap.engine.cache.memory; import com.ibatis.common.logging.Log; import com.ibatis.common.logging.LogFactory; import com.ibatis.sqlmap.engine.cache.CacheController; import com.ibatis.sqlmap.engine.cache.CacheModel; import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Properties; /** * Memory-based implementation of CacheController */ public class MemoryCacheController implements CacheController { private MemoryCacheLevel cacheLevel = MemoryCacheLevel.WEAK; private Map cache = Collections.synchronizedMap(new HashMap()); private static Log _log = LogFactory.getLog(MemoryCacheController.class); /** * Configures the cache * * @param props * Optionally can contain properties [reference-type=WEAK|SOFT|STRONG] */ public void configure(Properties props) { String refType = props.getProperty("reference-type"); if (refType == null) { refType = props.getProperty("referenceType"); } if (refType != null) { cacheLevel = MemoryCacheLevel.getByReferenceType(refType); } } /** * Add an object to the cache * * @param cacheModel * The cacheModel * @param key * The key of the object to be cached * @param value * The object to be cached */ public void putObject(CacheModel cacheModel, Object key, Object value) { Object reference = null; if (cacheLevel.equals(MemoryCacheLevel.WEAK)) { reference = new WeakReference(value); } else if (cacheLevel.equals(MemoryCacheLevel.SOFT)) { reference = new SoftReference(value); } else if (cacheLevel.equals(MemoryCacheLevel.STRONG)) { reference = new StrongReference(value); } if (_log.isDebugEnabled()) { _log.debug("{cache-memory} PutObject-[" + key + "]-[" + value + "]"); } cache.put(key, reference); } /** * Get an object out of the cache. * * @param cacheModel * The cache model * @param key * The key of the object to be returned * @return The cached object (or null) */ public Object getObject(CacheModel cacheModel, Object key) { Object value = null; Object ref = cache.get(key); if (ref != null) { if (ref instanceof StrongReference) { value = ((StrongReference)ref).get(); } else if (ref instanceof SoftReference) { value = ((SoftReference)ref).get(); } else if (ref instanceof WeakReference) { value = ((WeakReference)ref).get(); } } if (_log.isDebugEnabled()) { _log.debug("{cache-memory} GetObject-[" + key + "]-[" + value + "]"); } return value; } public Object removeObject(CacheModel cacheModel, Object key) { Object value = null; Object ref = cache.remove(key); if (ref != null) { if (ref instanceof StrongReference) { value = ((StrongReference)ref).get(); } else if (ref instanceof SoftReference) { value = ((SoftReference)ref).get(); } else if (ref instanceof WeakReference) { value = ((WeakReference)ref).get(); } } if (_log.isDebugEnabled()) { _log.debug("{cache-memory} RemoveObject-[" + key + "]-[" + value + "]"); } return value; } /** * Flushes the cache. * * @param cacheModel * The cache model */ public void flush(CacheModel cacheModel) { if (_log.isDebugEnabled()) { _log.debug("{cache-memory} Flush"); } cache.clear(); } /** * Class to implement a strong (permanent) reference. */ private static class StrongReference { private Object object; /** * StrongReference constructor for an object * * @param object - * the Object to store */ public StrongReference(Object object) { this.object = object; } /** * Getter to get the object stored in the StrongReference * * @return - the stored Object */ public Object get() { return object; } } } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira