ca.odell.glazedlists.io
Class CachingList
- EventListener, EventList<E>, List, ListEventListener<E>
An
EventList
that caches elements from its source
EventList
.
It is useful in cases when the
get(int)
method of an
EventList
is expensive. It can also be used when there are too many
elements to keep in memory simultaneously. For caching to be effective, object
access must be clustered.
This
EventList
caches the most recently requested
n elements.
By overriding the
preFetch(int)
method, you can modify this
CachingList to do predictive lookups for higher performance.
EventList Overview |
Writable: | yes |
Concurrency: | thread ready, not thread safe |
Performance: | reads: O(log N), writes O(log N) |
Memory: | O(N) |
Unit Tests: | N/A |
Issues: |
22
32
43
262
|
protected Object | fetch(int index, boolean recordHitsOrMisses) - Fetches a particular element.
|
Object | get(int index) -
|
float | getCacheHitRatio() - Gets the ratio of cache hits to cache misses.
|
int | getCacheHits() - Gets the total number of times that this list has fetched its result
from the cache rather than from the source list.
|
int | getCacheMisses() - Gets the total number of times that this list has fetched its result
from the source list rather than the cache.
|
protected boolean | isWritable() -
|
void | listChanged(ListEvent<E> listChanges) -
|
protected void | preFetch(int index) - Pre-fetches a set of data given the index that was directly requested.
|
int | size() -
|
add , addAll , clear , dispose , get , getSourceIndex , isWritable , listChanged , remove , removeAll , retainAll , set , size |
T[] toArray , add , add , addAll , addAll , addListEventListener , clear , contains , containsAll , equals , get , getPublisher , getReadWriteLock , hashCode , indexOf , isEmpty , iterator , lastIndexOf , listIterator , listIterator , remove , remove , removeAll , removeListEventListener , retainAll , set , size , subList , toArray , toString |
CachingList
public CachingList(EventList<E> source,
int maxSize)
source
- The source list to use to get values frommaxSize
- The maximum size of the cache
fetch
protected final Object fetch(int index,
boolean recordHitsOrMisses)
Fetches a particular element.
This might seem redundant with the existence of
get(int)
.
However, the goals of the methods are different. This method exists
to be called by
get(int)
or
preFetch(int)
.
This distinction allows users overriding this class a means of entry
retrieval which does not implicitly execute a pre-fetch. This is
particularly key for users overriding
preFetch(int)
index
- The index of the value to retrieverecordHitsOrMisses
- Whether to increment the hit/miss counters
(this should always be false
when called from
preFetch(int)
).
- The value associated with the given index,
or null if the index is not found.
getCacheHitRatio
public final float getCacheHitRatio()
Gets the ratio of cache hits to cache misses. This is a number between
0 and 1, where 0 means the cache is unused and 1 means the cache was
used exclusively.
getCacheHits
public final int getCacheHits()
Gets the total number of times that this list has fetched its result
from the cache rather than from the source list.
- The number of times that this cache provided the result
getCacheMisses
public final int getCacheMisses()
Gets the total number of times that this list has fetched its result
from the source list rather than the cache.
- The number of times that this cache couldn't provide the result
listChanged
public final void listChanged(ListEvent<E> listChanges)
preFetch
protected void preFetch(int index)
Pre-fetches a set of data given the index that was directly requested.
Each application that wishes to take advantage of pre-fetching should
implement this method in a way which best fits their particular use
cases. As such, no default pre-fetch behaviour could really be defined,
and thus this method is empty by default.
Because pre-fetching can modify the cache, child classes of CachingList
should use careful consideration of locking when implementing this method.
index
- The index that was requested from the cache
Glazed Lists, Copyright © 2003-2006 publicobject.com, O'Dell Engineering.
Documentation build by pbuilder at 2007-12-21 23:49