Package org.compiere.util
Class CacheMgt
java.lang.Object
org.compiere.util.CacheMgt
iDempiere global Cache Manager
- Version:
- $Id: CacheMgt.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $
- Author:
- Jorg Janke
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic CacheMgtget()Get global Cache ManagerGet info for cache instancesintGet Total Cached ElementsGet cache instancesbooleanIs there a cache instance for this table name?protected voidlocalNewRecord(String tableName, int Record_ID) New record notification for local cache instancesvoidNew record notification<K,V> Map<K, V> Register new CCache Instance.
This is use byCCacheand developer usually shouldn't call this directly.intreset()Do a cluster wide cache resetintDo a cluster wide cache reset for tableNameintDo a cluster wide cache reset for tableName with recordId keyintDo a cluster wide cache reset for tableName with keyintReset local CacheintresetLocalCache(String tableName, Integer recordId) Reset local CacheintresetLocalCache(String tableName, String key) Reset local CacheintresetLocalCacheWithAntiStampede(String tableName, int recordId) Reset the local cache fortableNamewith anti-stampede protection.intresetLocalCacheWithAntiStampede(String tableName, String key) Reset the local cache fortableNamewith anti-stampede protection.voidresumeTableCacheReset(String tableName) Clear suspend cache reset flag for tableNamestatic voidscheduleCacheReset(String cacheName, Object key, boolean newRecord, String trxName) Schedule cache reset after transaction commit.voidsuspendTableCacheReset(String tableName) Suspend cache reset operations for tableName (usually to improve performance for batch operations).
Caller must callresumeTableCacheReset(String)later to clear the suspend cache reset flag.toString()String RepresentationExtended String Representationbooleanunregister(CacheInterface instance) Un-Register Cache Instance
-
Field Details
-
MAX_SIZE
public static int MAX_SIZEDefault maximum cache size
-
-
Method Details
-
get
Get global Cache Manager- Returns:
- Cache Manager
-
register
Register new CCache Instance.
This is use byCCacheand developer usually shouldn't call this directly.- Parameters:
instance- Cachedistributed-- Returns:
- map for CCache
-
unregister
Un-Register Cache Instance- Parameters:
instance- Cache- Returns:
- true if removed
-
reset
public int reset()Do a cluster wide cache reset- Returns:
- number of deleted local cache entries;
0when a distributed cache service is active, since the reset is then dispatched fire-and-forget (remote nodes reset asynchronously)
-
reset
Do a cluster wide cache reset for tableName- Parameters:
tableName- table name- Returns:
- number of deleted local cache entries;
0when a distributed cache service is active, since the reset is then dispatched fire-and-forget (remote nodes reset asynchronously)
-
reset
Do a cluster wide cache reset for tableName with recordId key- Parameters:
tableName-Record_ID- record id for the cache entries to delete. pass -1 if you don't want to delete cache entries by record id- Returns:
- number of deleted local cache entries;
0when a distributed cache service is active andtableNameisn'tdebounced, since the reset is then dispatched fire-and-forget (remote nodes reset asynchronously)
-
reset
Do a cluster wide cache reset for tableName with key- Parameters:
tableName- cache namekey- cache key- Returns:
- number of deleted local cache entries;
0when a distributed cache service is active andtableNameisn'tdebounced, since the reset is then dispatched fire-and-forget (remote nodes reset asynchronously)
-
resetLocalCache
public int resetLocalCache()Reset local Cache- Returns:
- number of deleted cache entries
-
getInstancesAsArray
Get cache instances- Returns:
- cache instances
-
resetLocalCache
Reset local Cache- Parameters:
tableName- cache namerecordId- cache key- Returns:
- number of deleted cache entries
-
resetLocalCacheWithAntiStampede
Reset the local cache fortableNamewith anti-stampede protection. Called by the broadcast invalidation subscriber so nodes don't all hammer the DB simultaneously:- When
Cache.ResetStaggerMaxMsis > 0, the actual reset is deferred ontoAdempiere.getThreadPoolExecutor()'s delay queue by a deterministic delay — seecomputeStaggeredDelayMs()— so cluster members take a turn spread across theCache.ResetStaggerMaxMswindow instead of all reloading from the DB at the same millisecond. The queued delay costs no worker thread while pending, unlike blocking the caller withThread.sleep. In that case this method returns0immediately; the real reset count is only known once the queued task runs. - Uses a per-
guard keyAtomicBooleanin-flight guard: if a reset is already in progress (or queued) on this node for the same guard key, the duplicate is skipped.
- Parameters:
tableName- table to reset; whennullresets all cachesrecordId- integer key; -1 resets all entries for the table
- When
-
resetLocalCache
Reset local Cache- Parameters:
tableName- cache namekey- cache key- Returns:
- number of deleted cache entries
-
resetLocalCacheWithAntiStampede
Reset the local cache fortableNamewith anti-stampede protection. SeeresetLocalCacheWithAntiStampede(String, int)for the stagger/queueing and in-flight guard semantics.- Parameters:
tableName- table to resetkey- string key; empty string resets all entries for the table
-
localNewRecord
New record notification for local cache instances- Parameters:
tableName- table nameRecord_ID- record if applicable or 0 for all
-
getElementCount
public int getElementCount()Get Total Cached Elements- Returns:
- total cache element count
-
toString
String Representation -
toStringX
Extended String Representation- Returns:
- info
-
newRecord
New record notification- Parameters:
tableName-recordId-
-
getCacheInfos
Get info for cache instances- Returns:
- info for cache instances
-
hasCache
Is there a cache instance for this table name?- Parameters:
tableName-- Returns:
- boolean
-
suspendTableCacheReset
Suspend cache reset operations for tableName (usually to improve performance for batch operations).
Caller must callresumeTableCacheReset(String)later to clear the suspend cache reset flag.- Parameters:
tableName-
-
resumeTableCacheReset
Clear suspend cache reset flag for tableName- Parameters:
tableName-
-
scheduleCacheReset
public static void scheduleCacheReset(String cacheName, Object key, boolean newRecord, String trxName) Schedule cache reset after transaction commit. If trxName is null or transaction cannot be found, the cache reset will be scheduled immediately exceptions are logged and ignored- Parameters:
cacheName-key- - can be an Integer ID or String key, if key is -1, the whole cache will be resetnewRecord-trxName-
-