Java Doc for Cache.java in  » Cache » OSCache » com » opensymphony » oscache » base » 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
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » OSCache » com.opensymphony.oscache.base 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.opensymphony.oscache.base.Cache

All known Subclasses:   com.opensymphony.oscache.web.ServletCache,
Cache
public class Cache implements Serializable(Code)
Provides an interface to the cache itself. Creating an instance of this class will create a cache that behaves according to its construction parameters. The public API provides methods to manage objects in the cache and configure any cache event listeners.
version:
   $Revision: 468 $
author:
   Mike Cannon-Brookes
author:
   Todd Gochenour
author:
   Francois Beauregard
author:
   Chris Miller


Field Summary
final public static  StringNESTED_EVENT
     An event that origininated from within another event.
protected  EventListenerListlistenerList
     A list of all registered event listeners for this cache.

Constructor Summary
public  Cache(boolean useMemoryCaching, boolean unlimitedDiskCache, boolean overflowPersistence)
    
public  Cache(boolean useMemoryCaching, boolean unlimitedDiskCache, boolean overflowPersistence, boolean blocking, String algorithmClass, int capacity)
     Create a new Cache. If a valid algorithm class is specified, it will be used for this cache. Otherwise if a capacity is specified, it will use LRUCache. If no algorithm or capacity is specified UnlimitedCache is used.
See Also:   com.opensymphony.oscache.base.algorithm.LRUCache
See Also:   com.opensymphony.oscache.base.algorithm.UnlimitedCache
Parameters:
  useMemoryCaching - Specify if the memory caching is going to be used
Parameters:
  unlimitedDiskCache - Specify if the disk caching is unlimited
Parameters:
  overflowPersistence - Specify if the persistent cache is used in overflow only mode
Parameters:
  blocking - This parameter takes effect when a cache entry hasjust expired and several simultaneous requests try to retrieve it.

Method Summary
public  voidaddCacheEventListener(CacheEventListener listener)
     Register a listener for Cache events.
public  voidaddCacheEventListener(CacheEventListener listener, Class clazz)
     Register a listener for Cache events.
public  voidcancelUpdate(String key)
     Cancels any pending update for this cache entry.
protected  voidclear()
     Completely clears the cache.
protected  voidcompleteUpdate(String key)
     Removes the update state for the specified key and notifies any other threads that are waiting on this object.
public  voidflushAll(Date date)
     Flush all entries in the cache on the given date/time.
public  voidflushAll(Date date, String origin)
     Flush all entries in the cache on the given date/time.
public  voidflushEntry(String key)
     Flush the cache entry (if any) that corresponds to the cache key supplied. This call will flush the entry from the cache and remove the references to it from any cache groups that it is a member of.
public  voidflushEntry(String key, String origin)
     Flush the cache entry (if any) that corresponds to the cache key supplied. This call will mark the cache entry as flushed so that the next access to it will cause a NeedsRefreshException .
public  voidflushGroup(String group)
     Flushes all objects that belong to the supplied group.
public  voidflushGroup(String group, String origin)
     Flushes all unexpired objects that belong to the supplied group.
public  voidflushPattern(String pattern)
    
public  voidflushPattern(String pattern, String origin)
    
protected  CacheEntrygetCacheEntry(String key, EntryRefreshPolicy policy, String origin)
     Get an entry from this cache or create one if it doesn't exist.
public  EventListenerListgetCacheEventListenerList()
     Returns the list of all CacheEventListeners.
public  intgetCapacity()
    
public  ObjectgetFromCache(String key)
     Retrieve an object from the cache specifying its key.
Parameters:
  key - Key of the object in the cache.
public  ObjectgetFromCache(String key, int refreshPeriod)
     Retrieve an object from the cache specifying its key.
Parameters:
  key - Key of the object in the cache.
Parameters:
  refreshPeriod - How long before the object needs refresh.
public  ObjectgetFromCache(String key, int refreshPeriod, String cronExpiry)
     Retrieve an object from the cache specifying its key.
Parameters:
  key - Key of the object in the cache.
Parameters:
  refreshPeriod - How long before the object needs refresh.
public  intgetNbEntries()
    
protected  intgetNbUpdateState()
     Test support only: return the number of EntryUpdateState instances within the updateStates map.
public  PersistenceListenergetPersistenceListener()
     Retrieves the currently configured PersistenceListener.
public  intgetSize()
     the total number of cache entries held in this cache.
protected  EntryUpdateStategetUpdateState(String key)
     Get the updating cache entry from the update map.
public  booleanisFlushed(CacheEntry cacheEntry)
     Checks if the cache was flushed more recently than the CacheEntry provided.
protected  booleanisStale(CacheEntry cacheEntry, int refreshPeriod, String cronExpiry)
     Indicates whether or not the cache entry is stale.
Parameters:
  cacheEntry - The cache entry to test the freshness of.
Parameters:
  refreshPeriod - The maximum allowable age of the entry, in seconds.
Parameters:
  cronExpiry - A cron expression specifying absolute date(s) and/or time(s)that the cache entry should expire at.
public  voidputInCache(String key, Object content)
     Put an object in the cache specifying the key to use.
public  voidputInCache(String key, Object content, EntryRefreshPolicy policy)
     Put an object in the cache specifying the key and refresh policy to use.
public  voidputInCache(String key, Object content, String[] groups)
     Put in object into the cache, specifying both the key to use and the cache groups the object belongs to.
public  voidputInCache(String key, Object content, String[] groups, EntryRefreshPolicy policy, String origin)
     Put an object into the cache specifying both the key to use and the cache groups the object belongs to.
protected  voidreleaseUpdateState(EntryUpdateState state, String key)
     releases the usage that was made of the specified EntryUpdateState.
public  voidremoveCacheEventListener(CacheEventListener listener, Class clazz)
     Unregister a listener for Cache events.
public  voidremoveCacheEventListener(CacheEventListener listener)
     Unregister a listener for Cache events.
public  voidremoveEntry(String key)
     Completely removes a cache entry from the cache and its associated cache groups.
protected  voidremoveEntry(String key, String origin)
     Completely removes a cache entry from the cache and its associated cache groups.
public  voidsetCapacity(int capacity)
     Allows the capacity of the cache to be altered dynamically.
public  voidsetPersistenceListener(PersistenceListener listener)
     Set the listener to use for data persistence.

Field Detail
NESTED_EVENT
final public static String NESTED_EVENT(Code)
An event that origininated from within another event.



listenerList
protected EventListenerList listenerList(Code)
A list of all registered event listeners for this cache.




Constructor Detail
Cache
public Cache(boolean useMemoryCaching, boolean unlimitedDiskCache, boolean overflowPersistence)(Code)
Create a new Cache
Parameters:
  useMemoryCaching - Specify if the memory caching is going to be used
Parameters:
  unlimitedDiskCache - Specify if the disk caching is unlimited
Parameters:
  overflowPersistence - Specify if the persistent cache is used in overflow only mode



Cache
public Cache(boolean useMemoryCaching, boolean unlimitedDiskCache, boolean overflowPersistence, boolean blocking, String algorithmClass, int capacity)(Code)
Create a new Cache. If a valid algorithm class is specified, it will be used for this cache. Otherwise if a capacity is specified, it will use LRUCache. If no algorithm or capacity is specified UnlimitedCache is used.
See Also:   com.opensymphony.oscache.base.algorithm.LRUCache
See Also:   com.opensymphony.oscache.base.algorithm.UnlimitedCache
Parameters:
  useMemoryCaching - Specify if the memory caching is going to be used
Parameters:
  unlimitedDiskCache - Specify if the disk caching is unlimited
Parameters:
  overflowPersistence - Specify if the persistent cache is used in overflow only mode
Parameters:
  blocking - This parameter takes effect when a cache entry hasjust expired and several simultaneous requests try to retrieve it. Whileone request is rebuilding the content, the other requests will eitherblock and wait for the new content (blocking == true) orinstead receive a copy of the stale content so they don't have to wait(blocking == false). the default is false,which provides better performance but at the expense of slightly staledata being served.
Parameters:
  algorithmClass - The class implementing the desired algorithm
Parameters:
  capacity - The capacity




Method Detail
addCacheEventListener
public void addCacheEventListener(CacheEventListener listener)(Code)
Register a listener for Cache events. The listener must implement one of the child interfaces of the CacheEventListener interface.
Parameters:
  listener - The object that listens to events.
since:
   2.4



addCacheEventListener
public void addCacheEventListener(CacheEventListener listener, Class clazz)(Code)
Register a listener for Cache events. The listener must implement one of the child interfaces of the CacheEventListener interface.
Parameters:
  listener - The object that listens to events.
Parameters:
  clazz - the type of the listener to be addedCache.addCacheEventListener(CacheEventListener)



cancelUpdate
public void cancelUpdate(String key)(Code)
Cancels any pending update for this cache entry. This should only be called by the thread that is responsible for performing the update ie the thread that received the original NeedsRefreshException .

If a cache entry is not updated (via Cache.putInCache and this method is not called to let OSCache know the update will not be forthcoming, subsequent requests for this cache entry will either block indefinitely (if this is a new cache entry or cache.blocking=true), or forever get served stale content. Note however that there is no harm in cancelling an update on a key that either does not exist or is not currently being updated.
Parameters:
  key - The key for the cache entry in question.
throws:
  IllegalStateException - if the cache entry isn't in the state UPDATE_IN_PROGRESS




clear
protected void clear()(Code)
Completely clears the cache.



completeUpdate
protected void completeUpdate(String key)(Code)
Removes the update state for the specified key and notifies any other threads that are waiting on this object. This is called automatically by the Cache.putInCache method, so it is possible that no EntryUpdateState was hold when this method is called.
Parameters:
  key - The cache key that is no longer being updated.



flushAll
public void flushAll(Date date)(Code)
Flush all entries in the cache on the given date/time.
Parameters:
  date - The date at which all cache entries will be flushed.



flushAll
public void flushAll(Date date, String origin)(Code)
Flush all entries in the cache on the given date/time.
Parameters:
  date - The date at which all cache entries will be flushed.
Parameters:
  origin - The origin of this flush request (optional)



flushEntry
public void flushEntry(String key)(Code)
Flush the cache entry (if any) that corresponds to the cache key supplied. This call will flush the entry from the cache and remove the references to it from any cache groups that it is a member of. On completion of the flush, a CacheEntryEventType.ENTRY_FLUSHED event is fired.
Parameters:
  key - The key of the entry to flush



flushEntry
public void flushEntry(String key, String origin)(Code)
Flush the cache entry (if any) that corresponds to the cache key supplied. This call will mark the cache entry as flushed so that the next access to it will cause a NeedsRefreshException . On completion of the flush, a CacheEntryEventType.ENTRY_FLUSHED event is fired.
Parameters:
  key - The key of the entry to flush
Parameters:
  origin - The origin of this flush request (optional)



flushGroup
public void flushGroup(String group)(Code)
Flushes all objects that belong to the supplied group. On completion this method fires a CacheEntryEventType.GROUP_FLUSHED event.
Parameters:
  group - The group to flush



flushGroup
public void flushGroup(String group, String origin)(Code)
Flushes all unexpired objects that belong to the supplied group. On completion this method fires a CacheEntryEventType.GROUP_FLUSHED event.
Parameters:
  group - The group to flush
Parameters:
  origin - The origin of this flush event (optional)



flushPattern
public void flushPattern(String pattern)(Code)
Flush all entries with keys that match a given pattern
Parameters:
  pattern - The key must contain this given valueCache.flushGroup(String)



flushPattern
public void flushPattern(String pattern, String origin)(Code)
Flush all entries with keys that match a given pattern
Parameters:
  pattern - The key must contain this given value
Parameters:
  origin - The origin of this flush requestCache.flushGroup(String,String)



getCacheEntry
protected CacheEntry getCacheEntry(String key, EntryRefreshPolicy policy, String origin)(Code)
Get an entry from this cache or create one if it doesn't exist.
Parameters:
  key - The key of the cache entry
Parameters:
  policy - Object that implements refresh policy logic
Parameters:
  origin - The origin of request (optional) CacheEntry for the specified key.



getCacheEventListenerList
public EventListenerList getCacheEventListenerList()(Code)
Returns the list of all CacheEventListeners. the CacheEventListener's list of the Cache



getCapacity
public int getCapacity()(Code)
the maximum number of items to cache can hold.



getFromCache
public Object getFromCache(String key) throws NeedsRefreshException(Code)
Retrieve an object from the cache specifying its key.
Parameters:
  key - Key of the object in the cache. The object from cache
throws:
  NeedsRefreshException - Thrown when the object eitherdoesn't exist, or exists but is stale. When this exception occurs,the CacheEntry corresponding to the supplied key will be lockedand other threads requesting this entry will potentially be blockeduntil the caller repopulates the cache. If the caller choses notto repopulate the cache, they must instead callCache.cancelUpdate(String).



getFromCache
public Object getFromCache(String key, int refreshPeriod) throws NeedsRefreshException(Code)
Retrieve an object from the cache specifying its key.
Parameters:
  key - Key of the object in the cache.
Parameters:
  refreshPeriod - How long before the object needs refresh. Toallow the object to stay in the cache indefinitely, supply a valueof CacheEntry.INDEFINITE_EXPIRY. The object from cache
throws:
  NeedsRefreshException - Thrown when the object eitherdoesn't exist, or exists but is stale. When this exception occurs,the CacheEntry corresponding to the supplied key will be lockedand other threads requesting this entry will potentially be blockeduntil the caller repopulates the cache. If the caller choses notto repopulate the cache, they must instead callCache.cancelUpdate(String).



getFromCache
public Object getFromCache(String key, int refreshPeriod, String cronExpiry) throws NeedsRefreshException(Code)
Retrieve an object from the cache specifying its key.
Parameters:
  key - Key of the object in the cache.
Parameters:
  refreshPeriod - How long before the object needs refresh. Toallow the object to stay in the cache indefinitely, supply a valueof CacheEntry.INDEFINITE_EXPIRY.
Parameters:
  cronExpiry - A cron expression that specifies fixed date(s)and/or time(s) that this cache entry shouldexpire on. The object from cache
throws:
  NeedsRefreshException - Thrown when the object eitherdoesn't exist, or exists but is stale. When this exception occurs,the CacheEntry corresponding to the supplied key will be lockedand other threads requesting this entry will potentially be blockeduntil the caller repopulates the cache. If the caller choses notto repopulate the cache, they must instead callCache.cancelUpdate(String).



getNbEntries
public int getNbEntries()(Code)
Test support only: return the number of entries currently in the cache map



getNbUpdateState
protected int getNbUpdateState()(Code)
Test support only: return the number of EntryUpdateState instances within the updateStates map.



getPersistenceListener
public PersistenceListener getPersistenceListener()(Code)
Retrieves the currently configured PersistenceListener. the cache's PersistenceListener, or nullif no listener is configured.



getSize
public int getSize()(Code)
the total number of cache entries held in this cache.



getUpdateState
protected EntryUpdateState getUpdateState(String key)(Code)
Get the updating cache entry from the update map. If one is not found, create a new one (with state EntryUpdateState.NOT_YET_UPDATING ) and add it to the map.
Parameters:
  key - The cache key for this entry the CacheEntry that was found (or added to) the updatingEntriesmap.



isFlushed
public boolean isFlushed(CacheEntry cacheEntry)(Code)
Checks if the cache was flushed more recently than the CacheEntry provided. Used to determine whether to refresh the particular CacheEntry.
Parameters:
  cacheEntry - The cache entry which we're seeing whether to refresh Whether or not the cache has been flushed more recently than this cache entry was updated.



isStale
protected boolean isStale(CacheEntry cacheEntry, int refreshPeriod, String cronExpiry)(Code)
Indicates whether or not the cache entry is stale.
Parameters:
  cacheEntry - The cache entry to test the freshness of.
Parameters:
  refreshPeriod - The maximum allowable age of the entry, in seconds.
Parameters:
  cronExpiry - A cron expression specifying absolute date(s) and/or time(s)that the cache entry should expire at. If the cache entry was refreshed prior tothe most recent match for the cron expression, the entry will be considered stale. true if the entry is stale, false otherwise.



putInCache
public void putInCache(String key, Object content)(Code)
Put an object in the cache specifying the key to use.
Parameters:
  key - Key of the object in the cache.
Parameters:
  content - The object to cache.



putInCache
public void putInCache(String key, Object content, EntryRefreshPolicy policy)(Code)
Put an object in the cache specifying the key and refresh policy to use.
Parameters:
  key - Key of the object in the cache.
Parameters:
  content - The object to cache.
Parameters:
  policy - Object that implements refresh policy logic



putInCache
public void putInCache(String key, Object content, String[] groups)(Code)
Put in object into the cache, specifying both the key to use and the cache groups the object belongs to.
Parameters:
  key - Key of the object in the cache
Parameters:
  content - The object to cache
Parameters:
  groups - The cache groups to add the object to



putInCache
public void putInCache(String key, Object content, String[] groups, EntryRefreshPolicy policy, String origin)(Code)
Put an object into the cache specifying both the key to use and the cache groups the object belongs to.
Parameters:
  key - Key of the object in the cache
Parameters:
  groups - The cache groups to add the object to
Parameters:
  content - The object to cache
Parameters:
  policy - Object that implements the refresh policy logic



releaseUpdateState
protected void releaseUpdateState(EntryUpdateState state, String key)(Code)
releases the usage that was made of the specified EntryUpdateState. When this reaches zero, the entry is removed from the map.
Parameters:
  state - the state to release the usage of
Parameters:
  key - the associated key.



removeCacheEventListener
public void removeCacheEventListener(CacheEventListener listener, Class clazz)(Code)
Unregister a listener for Cache events.
Parameters:
  listener - The object that currently listens to events.
Parameters:
  clazz - The registrated class of listening object.Cache.removeCacheEventListener(CacheEventListener)



removeCacheEventListener
public void removeCacheEventListener(CacheEventListener listener)(Code)
Unregister a listener for Cache events.
Parameters:
  listener - The object that currently listens to events.
since:
   2.4



removeEntry
public void removeEntry(String key)(Code)
Completely removes a cache entry from the cache and its associated cache groups.
Parameters:
  key - The key of the entry to remove.



removeEntry
protected void removeEntry(String key, String origin)(Code)
Completely removes a cache entry from the cache and its associated cache groups.
Parameters:
  key - The key of the entry to remove.
Parameters:
  origin - The origin of this remove request.



setCapacity
public void setCapacity(int capacity)(Code)
Allows the capacity of the cache to be altered dynamically. Note that some cache implementations may choose to ignore this setting (eg the UnlimitedCache ignores this call).
Parameters:
  capacity - the maximum number of items to hold in the cache.



setPersistenceListener
public void setPersistenceListener(PersistenceListener listener)(Code)
Set the listener to use for data persistence. Only one PersistenceListener can be configured per cache.
Parameters:
  listener - The implementation of a persistance listener



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 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.