Java Doc for Cache.java in  » Forum » nemesis-forum » org » nemesis » forum » 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 » Forum » nemesis forum » org.nemesis.forum.util.cache 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.nemesis.forum.util.cache.Cache

Cache
public class Cache implements Cacheable(Code)


Field Summary
protected  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  HashMapcachedObjectsHash
     Maintains the hash of cached objects.
protected static  longcurrentTime
     One of the major potential bottlenecks of the cache is performing System.currentTimeMillis() for every cache get operation.
protected  LinkedListlastAccessedList
     Linked list to maintain order that cache objects are accessed in, most used to least used.
protected  longmaxLifetime
     Maximum length of time objects can exist in cache before expiring.
protected  intmaxSize
     Maximum size in bytes that the cache can grow to.
protected  intsize
     Maintains the current size of the cache in bytes.
protected static  CacheTimertimer
     A cache timer updates the current time once a second in a seperate thread.

Constructor Summary
public  Cache()
     Create a new cache with default values.
public  Cache(int maxSize)
     Create a new cache and specify the maximum size for the cache in bytes.
public  Cache(long maxLifetime)
     Create a new cache and specify the maximum lifetime of objects.
public  Cache(int maxSize, long maxLifetime)
     Create a new cache and specify the maximum size of for the cache in bytes, and the maximum lifetime of objects.

Method Summary
public synchronized  voidadd(Object key, Cacheable object)
     Adds a new Cacheable object to the cache.
public synchronized  voidclear()
     Clears the cache of all objects.
public synchronized  Cacheableget(Object key)
     Gets an object from cache.
public  longgetCacheHits()
     Returns the number of cache hits.
public  longgetCacheMisses()
     Returns the number of cache misses.
public  intgetMaxSize()
     Returns the maximum size of the cache in bytes.
public synchronized  intgetNumElements()
     Returns the number of objects in the cache.
public  intgetSize()
     Returns the current size of the cache in bytes.
public synchronized  voidremove(Object key)
     Removes an object from cache.
public  voidsetMaxSize(int maxSize)
     Sets the maximum size of the cache in bytes.
public  Collectionvalues()
     Returns a collection view of the values contained in the cache.

Field Detail
ageList
protected 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.




cachedObjectsHash
protected HashMap cachedObjectsHash(Code)
Maintains the hash of cached objects. Hashing provides the best performance for fast lookups.



currentTime
protected static long currentTime(Code)
One of the major potential bottlenecks of the cache is performing System.currentTimeMillis() for every cache get operation. Instead, we maintain a global timestamp that gets updated once a second. This means that cache expirations can be no more than one second accurate.



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



maxLifetime
protected long maxLifetime(Code)
Maximum length of time objects can exist in cache before expiring. Default is that objects have no maximum lifetime.



maxSize
protected int maxSize(Code)
Maximum size in bytes that the cache can grow to. Default maximum size is 128 K.



size
protected int size(Code)
Maintains the current size of the cache in bytes.



timer
protected static CacheTimer timer(Code)
A cache timer updates the current time once a second in a seperate thread.




Constructor Detail
Cache
public Cache()(Code)
Create a new cache with default values. Default cache size is 128K with no maximum lifetime.



Cache
public Cache(int maxSize)(Code)
Create a new cache and specify the maximum size for the cache in bytes. Items added to the cache will have no maximum lifetime.
Parameters:
  maxSize - the maximum size of the cache in bytes.



Cache
public Cache(long maxLifetime)(Code)
Create a new cache and specify the maximum lifetime of objects. The time should be specified in milleseconds. The minimum lifetime of any cache object is 1000 milleseconds (1 second). Additionally, cache expirations have a 1000 millesecond resolution, which means that all objects are guaranteed to be expired within 1000 milliseconds of their maximum lifetime.
Parameters:
  maxLifetime - the maximum amount of time objects can exist incache before being deleted.



Cache
public Cache(int maxSize, long maxLifetime)(Code)
Create a new cache and specify the maximum size of for the cache in bytes, and the maximum lifetime of objects.
Parameters:
  maxSize - the maximum size of the cache in bytes.
Parameters:
  maxLifetime - the maximum amount of time objects can exist incache before being deleted.




Method Detail
add
public synchronized void add(Object key, Cacheable object)(Code)
Adds a new Cacheable object to the cache. The key must be unique.
Parameters:
  key - a unique key for the object being put into cache.
Parameters:
  object - the Cacheable object to put into cache.



clear
public synchronized void clear()(Code)
Clears the cache of all objects. The size of the cache is reset to 0.



get
public synchronized Cacheable get(Object key)(Code)
Gets an object from cache. This method will return null under two conditions:
  • The object referenced by the key was never added to cache.
  • The object referenced by the key has expired from cache.

Parameters:
  key - the unique key of the object to get. the Cacheable object corresponding to unique key.



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.




getMaxSize
public int getMaxSize()(Code)
Returns the maximum size of the cache in bytes. If the cache grows too large, the least frequently used items will automatically be deleted so that the cache size doesn't exceed the maximum. the maximum size of the cache in bytes.



getNumElements
public synchronized int getNumElements()(Code)
Returns the number of objects in the cache. the number of objects in the cache.



getSize
public int getSize()(Code)
Returns the current size of the cache in bytes. the size of the cache in bytes.



remove
public synchronized void remove(Object key)(Code)
Removes an object from cache.
Parameters:
  key - the unique key of the object to remove.



setMaxSize
public void setMaxSize(int maxSize)(Code)
Sets the maximum size of the cache in bytes. If the cache grows too large, the least frequently used items will automatically be deleted so that the cache size doesn't exceed the maximum.
Parameters:
  maxSize - the maximum size of the cache in bytes.



values
public Collection values()(Code)
Returns a collection view of the values contained in the cache. The Collection is unmodifiable to prevent cache integrity issues. a Collection of the cache entries.



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.