Java Doc for DefaultCache.java in  » Net » openfire » org » jivesoftware » util » cache » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » openfire » org.jivesoftware.util.cache 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.jivesoftware.util.cache.DefaultCache

DefaultCache
public class DefaultCache implements Cache<K, V>(Code)
Default, non-distributed implementation of the Cache interface. The algorithm for cache is as follows: a HashMap is maintained for fast object lookup. Two linked lists are maintained: one keeps objects in the order they are accessed from cache, the other keeps objects in the order they were originally added to cache. When objects are added to cache, they are first wrapped by a CacheObject which maintains the following pieces of information:
  • The size of the object (in bytes).
  • A pointer to the node in the linked list that maintains accessed order for the object. Keeping a reference to the node lets us avoid linear scans of the linked list.
  • A pointer to the node in the linked list that maintains the age of the object in cache. Keeping a reference to the node lets us avoid linear scans of the linked list.

To get an object from cache, a hash lookup is performed to get a reference to the CacheObject that wraps the real object we are looking for. The object is subsequently moved to the front of the accessed linked list and any necessary cache cleanups are performed. Cache deletion and expiration is performed as needed.
author:
   Matt Tucker



Field Summary
protected  org.jivesoftware.util.LinkedListageList
     Linked list to maintain time that cache objects were initially added to the cache, most recently added to oldest added.
protected  longcacheHitscacheMisses
     Maintain the number of cache hits and misses.
protected  org.jivesoftware.util.LinkedListlastAccessedList
     Linked list to maintain order that cache objects are accessed in, most used to least used.
protected  Map<K, DefaultCache.CacheObject<V>>map
     The map the keys and values are stored in.
protected  longmaxLifetime
     Maximum length of time objects can exist in cache before expiring.

Constructor Summary
public  DefaultCache(String name, long maxSize, long maxLifetime)
     Create a new default cache and specify the maximum size of for the cache in bytes, and the maximum lifetime of objects.
Parameters:
  name - a name for the cache.
Parameters:
  maxSize - the maximum size of the cache in bytes.

Method Summary
public synchronized  voidclear()
    
public  booleancontainsKey(Object key)
    
public  booleancontainsValue(Object value)
    
final protected  voidcullCache()
     Removes objects from cache if the cache is too full.
protected  voiddeleteExpiredEntries()
     Clears all entries out of cache where the entries are older than the maximum defined age.
public  Set<Entry<K, V>>entrySet()
    
public synchronized  Vget(Object key)
    
public  longgetCacheHits()
     Returns the number of cache hits.
public  longgetCacheMisses()
     Returns the number of cache misses.
public  intgetCacheSize()
     Returns the size of the cache contents in bytes.
public  longgetMaxCacheSize()
     Returns the maximum size of the cache (in bytes).
public  longgetMaxLifetime()
     Returns the maximum number of milleseconds that any object can live in cache.
public  StringgetName()
     Returns the name of this cache.
public  booleanisEmpty()
    
public  Set<K>keySet()
    
public synchronized  Vput(K key, V value)
    
public  voidputAll(Map<? extends K, ? extends V> map)
    
public synchronized  Vremove(Object key)
    
public  voidsetMaxCacheSize(int maxCacheSize)
     Sets the maximum size of the cache.
public  voidsetMaxLifetime(long maxLifetime)
     Sets the maximum number of milleseconds that any object can live in cache.
public  voidsetName(String name)
     Sets the name of this cache.
public  intsize()
    
public  Collection<V>values()
    

Field Detail
ageList
protected org.jivesoftware.util.LinkedList ageList(Code)
Linked list to maintain time that cache objects were initially added to the cache, most recently added to oldest added.



cacheHitscacheMisses
protected long cacheHitscacheMisses(Code)
Maintain the number of cache hits and misses. A cache hit occurs every time the get method is called and the cache contains the requested object. A cache miss represents the opposite occurence.

Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.




lastAccessedList
protected org.jivesoftware.util.LinkedList lastAccessedList(Code)
Linked list to maintain order that cache objects are accessed in, most used to least used.



map
protected Map<K, DefaultCache.CacheObject<V>> map(Code)
The map the keys and values are stored in.



maxLifetime
protected long maxLifetime(Code)
Maximum length of time objects can exist in cache before expiring.




Constructor Detail
DefaultCache
public DefaultCache(String name, long maxSize, long maxLifetime)(Code)
Create a new default cache and specify the maximum size of for the cache in bytes, and the maximum lifetime of objects.
Parameters:
  name - a name for the cache.
Parameters:
  maxSize - the maximum size of the cache in bytes. -1 means the cachehas no max size.
Parameters:
  maxLifetime - the maximum amount of time objects can exist incache before being deleted. -1 means objects never expire.




Method Detail
clear
public synchronized void clear()(Code)



containsKey
public boolean containsKey(Object key)(Code)



containsValue
public boolean containsValue(Object value)(Code)



cullCache
final protected void cullCache()(Code)
Removes objects from cache if the cache is too full. "Too full" is defined as within 3% of the maximum cache size. Whenever the cache is is too big, the least frequently used elements are deleted until the cache is at least 10% empty.



deleteExpiredEntries
protected void deleteExpiredEntries()(Code)
Clears all entries out of cache where the entries are older than the maximum defined age.



entrySet
public Set<Entry<K, V>> entrySet()(Code)



get
public synchronized V get(Object key)(Code)



getCacheHits
public long getCacheHits()(Code)
Returns the number of cache hits. A cache hit occurs every time the get method is called and the cache contains the requested object.

Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient. the number of cache hits.




getCacheMisses
public long getCacheMisses()(Code)
Returns the number of cache misses. A cache miss occurs every time the get method is called and the cache does not contain the requested object.

Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient. the number of cache hits.




getCacheSize
public int getCacheSize()(Code)
Returns the size of the cache contents in bytes. This value is only a rough approximation, so cache users should expect that actual VM memory used by the cache could be significantly higher than the value reported by this method. the size of the cache contents in bytes.



getMaxCacheSize
public long getMaxCacheSize()(Code)
Returns the maximum size of the cache (in bytes). If the cache grows larger than the max size, the least frequently used items will be removed. If the max cache size is set to -1, there is no size limit. the maximum size of the cache (-1 indicates unlimited max size).



getMaxLifetime
public long getMaxLifetime()(Code)
Returns the maximum number of milleseconds that any object can live in cache. Once the specified number of milleseconds passes, the object will be automatically expried from cache. If the max lifetime is set to -1, then objects never expire. the maximum number of milleseconds before objects are expired.



getName
public String getName()(Code)
Returns the name of this cache. The name is completely arbitrary and used only for display to administrators. the name of this cache.



isEmpty
public boolean isEmpty()(Code)



keySet
public Set<K> keySet()(Code)



put
public synchronized V put(K key, V value)(Code)



putAll
public void putAll(Map<? extends K, ? extends V> map)(Code)



remove
public synchronized V remove(Object key)(Code)



setMaxCacheSize
public void setMaxCacheSize(int maxCacheSize)(Code)
Sets the maximum size of the cache. If the cache grows larger than the max size, the least frequently used items will be removed. If the max cache size is set to -1, there is no size limit.
Parameters:
  maxCacheSize - the maximum size of this cache (-1 indicates unlimited max size).



setMaxLifetime
public void setMaxLifetime(long maxLifetime)(Code)
Sets the maximum number of milleseconds that any object can live in cache. Once the specified number of milleseconds passes, the object will be automatically expried from cache. If the max lifetime is set to -1, then objects never expire.
Parameters:
  maxLifetime - the maximum number of milleseconds before objects are expired.



setName
public void setName(String name)(Code)
Sets the name of this cache.
Parameters:
  name - the name of this cache.



size
public int size()(Code)



values
public Collection<V> values()(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.