mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-16 23:55:23 +01:00
Made the class Javadoc of AbstractRegionQueryCache sane.
This commit is contained in:
parent
df54d4de91
commit
4e008f6c52
@ -21,25 +21,41 @@
|
|||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To facilitate performing regions-containing-point lookups from multiple stack frames
|
* A simple cache to reduce hits to the region manager when region information
|
||||||
* but within the same context (the same event), a cache is important in preventing the
|
* is needed for the same location in the same event context.
|
||||||
* need for redundant lookups made for the same point. This class serves as such a cache.
|
|
||||||
* <p>
|
* <p>
|
||||||
* A key needs to be selected to store cache entries against. The best key is one that
|
* If two or more pieces of code (such as from different programs or plugins)
|
||||||
* is highly temporal, and would represent a certain "snapshot in time," such as
|
* need to ask the question of "which regions contain this point" within the
|
||||||
* an event object. The event objects are indexed in this class using weak references,
|
* same event (such as when a player breaks a block), it is ideal that a query
|
||||||
* and they will be removed by the garbage collector automatically. Because it
|
* is only performed once and a cached answer is returned for the subsequent
|
||||||
* <em>is</em> a weak reference, the key object needs to be held somewhere with a strong
|
* requests for this information (but only within the same context or event!).
|
||||||
* reference until the "snapshot" ends.
|
* This is because queries to the region manager are often demanding and it
|
||||||
|
* would be taxing to perform the same search more than once. The purpose of
|
||||||
|
* this class is to facilitate exactly that.
|
||||||
* <p>
|
* <p>
|
||||||
* This class is abstract because implementing class should provide methods to check
|
* In order for this cache to work, a key must be generated for each query to
|
||||||
* against a standard key object. This cache itself is thread-safe.
|
* this cache. If two pieces of code need to execute the same region query
|
||||||
|
* during the same event (consider this at time A), both pieces of code must
|
||||||
|
* give the instance of this class the exact same 'key' object in order for the
|
||||||
|
* second calling piece of code to receive the cached result. However, once that
|
||||||
|
* event has been processed and time has moved on (proceeding to time X+1), that
|
||||||
|
* previously chosen key object must not ever be used again, otherwise it may
|
||||||
|
* return the results that were found at time X, which may be out of date.
|
||||||
|
* <p>
|
||||||
|
* Weak references are used to refer to that key object, and so whatever key
|
||||||
|
* object is chosen can be properly garbage collected once it is no longer
|
||||||
|
* needed outside the context of this cache.
|
||||||
|
* <p>
|
||||||
|
* This cache itself is thread-safe.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractRegionQueryCache {
|
public abstract class AbstractRegionQueryCache {
|
||||||
|
|
||||||
private final WeakHashMap<Object, RegionQueryCacheEntry> cache =
|
private final WeakHashMap<Object, RegionQueryCacheEntry> cache =
|
||||||
new WeakHashMap<Object, RegionQueryCacheEntry>();
|
new WeakHashMap<Object, RegionQueryCacheEntry>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a copy of this cache.
|
||||||
|
*/
|
||||||
public AbstractRegionQueryCache() {
|
public AbstractRegionQueryCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user