01: /*
02: * NEMESIS-FORUM.
03: * Copyright (C) 2002 David Laurent(lithium2@free.fr). All rights reserved.
04: *
05: * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
06: *
07: * Copyright (C) 2001 Yasna.com. All rights reserved.
08: *
09: * Copyright (C) 2000 CoolServlets.com. All rights reserved.
10: *
11: * NEMESIS-FORUM. is free software; you can redistribute it and/or
12: * modify it under the terms of the Apache Software License, Version 1.1,
13: * or (at your option) any later version.
14: *
15: * NEMESIS-FORUM core framework, NEMESIS-FORUM backoffice, NEMESIS-FORUM frontoffice
16: * application are parts of NEMESIS-FORUM and are distributed under
17: * same terms of licence.
18: *
19: *
20: * NEMESIS-FORUM includes software developed by the Apache Software Foundation (http://www.apache.org/)
21: * and software developed by CoolServlets.com (http://www.coolservlets.com).
22: * and software developed by Yasna.com (http://www.yasna.com).
23: *
24: */
25:
26: package org.nemesis.forum.util.cache;
27:
28: import org.nemesis.forum.util.LinkedListNode;
29:
30: /**
31: * Wrapper for all objects put into cache. It's primary purpose is to maintain
32: * references to the linked lists that maintain the creation time of the object
33: * and the ordering of the most used objects.
34: *
35: * This class is optimized for speed rather than strictly correct encapsulation.
36: */
37: public final class CacheObject {
38:
39: /**
40: * Underlying object wrapped by the CacheObject.
41: */
42: public Cacheable object;
43:
44: /**
45: * The size of the Cacheable object. The size of the Cacheable
46: * object is only computed once when it is added to the cache. This makes
47: * the assumption that once objects are added to cache, they are mostly
48: * read-only and that their size does not change significantly over time.
49: */
50: public int size;
51:
52: /**
53: * A reference to the node in the cache order list. We keep the reference
54: * here to avoid linear scans of the list. Every time the object is
55: * accessed, the node is removed from its current spot in the list and
56: * moved to the front.
57: */
58: public LinkedListNode lastAccessedListNode;
59:
60: /**
61: * A reference to the node in the age order list. We keep the reference
62: * here to avoid linear scans of the list. The reference is used if the
63: * object has to be deleted from the list.
64: */
65: public LinkedListNode ageListNode;
66:
67: /**
68: * Creates a new cache object wrapper. The size of the Cacheable object
69: * must be passed in in order to prevent another possibly expensive
70: * lookup by querying the object itself for its size.<p>
71: *
72: * @param object the underlying Cacheable object to wrap.
73: * @param size the size of the Cachable object in bytes.
74: */
75: public CacheObject(Cacheable object, int size) {
76: this.object = object;
77: this.size = size;
78: }
79: }
|