Java Doc for ResultsCache.java in  » Database-ORM » beankeeper » hu » netmind » persistence » 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 » Database ORM » beankeeper » hu.netmind.persistence 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   hu.netmind.persistence.ResultsCache

ResultsCache
public class ResultsCache (Code)
This is an implementation of an intelligent, configurationless read-only cache with change detection.
The main design point is that it does not require any configuration from the user. It's task is to cache result sets up to a previously given deadline, and when that is reached, clear from cache. When the same result is referenced, the deadline may be moved further into the future. Memory management is dynamic. When a resultset arives into the cache, it is always cached, but if the cache detects, that there is "not enough memory" (see below) left, it may clear some entries before their their deadline is reached.
So basically one does not have to configure the size of the cache because it assumes that if a resultset was not recalled in a given timeframe, the overhead of selecting from database is acceptable (rather than always using a predetemined size for the cache, hoping to achieve more cache hits). Also, memory adapts to usage: When the load is low, it is more likely, that only a few resultsets are in the cache, because they expire, and are not likely to be hit anyway. But if the load rises, more and more results get into the cache, the likelyhood of a hit also rises, together with the memory allocation.
The cache determines whether there is enough memory by checking the raw bytes free, and also computes the ratio of allocated vs. free memory. If this ratio is below a given threshold, then there is enough memory. The theory is, that the Java VM will allocate more heap when this ratio is sufficiently small (usually around 60-70%). This leaves two cases:
  • If the cache's ratio is less than the VM's, than the cache will not force the VM to allocate more space, which in turn means, that the cache will not grow, although the VM could allocate more memory.
  • If this ratio is more than the VM's, than the cache will potentially force the VM to allocate new memory, potentially eating the memory away from more important tasks.
The cache uses the first non-agressive algorithm. The cache itself will not cause the VM to allocate more heap, but if the application uses more memory the cache will use proportionally more memory for it's own cause. Note: The VM tries to maintain free/used ratio between appr. 30-70%.
This cache specializes to store only current searches' result (rather than current and historical results). This is because in the case of current results, the cache can effectively compute the interval the result is valid. When determining whether a statement's result is in the cache, the cache searches all entries (which are all current), and if the statements serial is above or equals to the result's start serial (the serial of the first query which caused the entry to be created), then the result is valid for that query. If a query is received for which the result may depend on changes inside the transaction, which are not yet visible to the other transactions, then this query is not handled. This is mainly because handling transaction-dependent result sets would be a large overhead for the cache, with little benefit if at all.
In effect, cache hits will occur mostly, when the same non-historical query, for a common table (not frequently changed) is run multiple times in short period of time.
author:
   Brautigam Robert
version:
   Revision: $Revision$



Constructor Summary
public  ResultsCache(StoreContext context)
    

Method Summary
public  voidaddEntry(QueryStatement stmt, Limits limits, SearchResult result)
     Add an entry to the cache.
public  voidclear()
     Clear the cache.
public  SearchResultgetEntry(QueryStatement stmt, Limits limits)
     Get an entry from the cache.
Parameters:
  stmt - The statement to look for.
Parameters:
  limits - The limits of the query.
public  voidinit()
     Initialize the cache with the current serial.
public  voidupdateEntries(String tableName, Long modifySerial)
     Tell the cache, that a table was updated.


Constructor Detail
ResultsCache
public ResultsCache(StoreContext context)(Code)




Method Detail
addEntry
public void addEntry(QueryStatement stmt, Limits limits, SearchResult result)(Code)
Add an entry to the cache.
Parameters:
  stmt - The statement source of result.
Parameters:
  limits - The limits of result.
Parameters:
  result - The SearchResult object.



clear
public void clear()(Code)
Clear the cache.



getEntry
public SearchResult getEntry(QueryStatement stmt, Limits limits)(Code)
Get an entry from the cache.
Parameters:
  stmt - The statement to look for.
Parameters:
  limits - The limits of the query. A SearchResult object if the query was cached, null otherwise.



init
public void init()(Code)
Initialize the cache with the current serial.



updateEntries
public void updateEntries(String tableName, Long modifySerial)(Code)
Tell the cache, that a table was updated. If an object is updated, the old resultsets could be theoretically kept, with an other time control, but empirically that does not add to cache hits, because more often, only current resultsets are selected.
Parameters:
  tableName - The table to update.
Parameters:
  modifySerial - The modification serial of table.



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.