001: /**
002: * $RCSfile: CacheObject.java,v $
003: * $Revision: 1.3 $
004: * $Date: 2006/01/07 00:21:06 $
005: *
006: * Copyright (C) 2000 CoolServlets.com. All rights reserved.
007: *
008: * ===================================================================
009: * The Apache Software License, Version 1.1
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions
013: * are met:
014: *
015: * 1. Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * 2. Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in
020: * the documentation and/or other materials provided with the
021: * distribution.
022: *
023: * 3. The end-user documentation included with the redistribution,
024: * if any, must include the following acknowledgment:
025: * "This product includes software developed by
026: * CoolServlets.com (http://www.Yasna.com)."
027: * Alternately, this acknowledgment may appear in the software itself,
028: * if and wherever such third-party acknowledgments normally appear.
029: *
030: * 4. The names "Jive" and "CoolServlets.com" must not be used to
031: * endorse or promote products derived from this software without
032: * prior written permission. For written permission, please
033: * contact webmaster@Yasna.com.
034: *
035: * 5. Products derived from this software may not be called "Jive",
036: * nor may "Jive" appear in their name, without prior written
037: * permission of CoolServlets.com.
038: *
039: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
040: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
041: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
042: * DISCLAIMED. IN NO EVENT SHALL COOLSERVLETS.COM OR
043: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
044: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
045: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
046: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
047: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
048: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
049: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
050: * SUCH DAMAGE.
051: * ====================================================================
052: *
053: * This software consists of voluntary contributions made by many
054: * individuals on behalf of CoolServlets.com. For more information
055: * on CoolServlets.com, please see <http://www.Yasna.com>.
056: */package com.Yasna.util;
057:
058: /**
059: * Wrapper for all objects put into cache. It's primary purpose is to maintain
060: * references to the linked lists that maintain the creation time of the object
061: * and the ordering of the most used objects.
062: *
063: * This class is optimized for speed rather than strictly correct encapsulation.
064: */
065: public final class CacheObject {
066:
067: /**
068: * Underlying object wrapped by the CacheObject.
069: */
070: public Cacheable object;
071:
072: /**
073: * The size of the Cacheable object. The size of the Cacheable
074: * object is only computed once when it is added to the cache. This makes
075: * the assumption that once objects are added to cache, they are mostly
076: * read-only and that their size does not change significantly over time.
077: */
078: public int size;
079:
080: /**
081: * A reference to the node in the cache order list. We keep the reference
082: * here to avoid linear scans of the list. Every time the object is
083: * accessed, the node is removed from its current spot in the list and
084: * moved to the front.
085: */
086: public LinkedListNode lastAccessedListNode;
087:
088: /**
089: * A reference to the node in the age order list. We keep the reference
090: * here to avoid linear scans of the list. The reference is used if the
091: * object has to be deleted from the list.
092: */
093: public LinkedListNode ageListNode;
094:
095: /**
096: * Creates a new cache object wrapper. The size of the Cacheable object
097: * must be passed in in order to prevent another possibly expensive
098: * lookup by querying the object itself for its size.<p>
099: *
100: * @param object the underlying Cacheable object to wrap.
101: * @param size the size of the Cachable object in bytes.
102: */
103: public CacheObject(Cacheable object, int size) {
104: this.object = object;
105: this.size = size;
106: }
107: }
|