|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.webSvr.util.SearchResultSimpleCache
public final class SearchResultSimpleCache
Bean for cached search results. Uses SearchUtils.doRelatedExhibitsSearch() to compute results lazily and caches the results.
Cache size is limited at most in proportion to the number of exhibits (keyed from their names and from canonicalised forms of those names for shared results) and may be capped to a fixed ceiling below that to retain only the most popular lookups.
| Field Summary | |
|---|---|
static int |
ABS_MAX_RESULTS
Absolute maximum number of results to store/cache per exhibit. |
private MemoryTools.CacheMiniMap<java.lang.Integer,java.util.List<Name.ExhibitFull>> |
fromCanonKey
Map from condensed canonical key to immutable ordered list of full-name results, best match first. |
private MemoryTools.CacheMiniMap<Name.ExhibitFull,java.util.List<Name.ExhibitFull>> |
fromFullName
Map from full exhibit name to immutable ordered list of full-name results, best match first. |
private static DataSourceBean.AEPLinkedKey |
fullSearchCacheKey
Private lookup key for full searches of similar items; never null. |
| Constructor Summary | |
|---|---|
SearchResultSimpleCache()
|
|
| Method Summary | |
|---|---|
private static int |
computeCacheMaxSize()
Compute maximum cache size, partly based on heap size; strictly positive. |
static Name |
computeRawSearchTermFromExhibitName(Name.ExhibitFull exhibitFullName)
Compute the (immutable) raw core lookup term in the by-word index from text in the exhibit name itself; never null. |
static java.util.List<Name.ExhibitFull> |
doCachedCatPageSimilarItems(DataSourceBean dsb,
Name.ExhibitFull exhibitName,
int maxToShow)
Do cached lookup for cat page "similar items"; never null. |
static java.util.concurrent.Future<java.util.List<Name.ExhibitFull>> |
doCachedCatPageSimilarItemsFuture(DataSourceBean dsb,
Name.ExhibitFull exhibitFullName,
int maxResults)
Do cached search lookup as for doCachedCatPageSimilarItems() but asynchronously; never null. |
static java.util.concurrent.Future<java.util.List<Name.ExhibitFull>> |
doCachedCatPageSimilarItemsFuture(DataSourceBean dsb,
Name.ExhibitFull exhibitFullName,
int maxResults,
boolean discardable)
Do cached search lookup as for doCachedCatPageSimilarItems() but asynchronously; never null. |
java.util.List<Name.ExhibitFull> |
getRelatedExhibits(DataSourceBean dataSource,
Name.ExhibitFull exhibitFullName,
int maxResults)
Do cached search lookup on given full exhibit name returning full exhibit name results; never null. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final MemoryTools.CacheMiniMap<Name.ExhibitFull,java.util.List<Name.ExhibitFull>> fromFullName
Capped size to minimise memory footprint while still giving good performance. Falling through the cache and doing the query from scratch shouldn't be hideously slow anyway.
Since the actual cached items are small (even compared to Map.Entry overheads), a relatively large number can be cached and it is not worth a complex high-overhead scheme, eg using SoftReferences, to manage them.
Limit maximum cache size in proportion to heap size; strictly positive. Aim to allow ~10000 entries per 1GB of heap space (at initialisation of this instance), with a minimum of tens/hundreds to cover popular pages, etc, at relatively low memory cost.
We're prepared to discard everything under acute memory pressure.
private final MemoryTools.CacheMiniMap<java.lang.Integer,java.util.List<Name.ExhibitFull>> fromCanonKey
public static final int ABS_MAX_RESULTS
If the catalogue page logic actually uses this value as the maximum request size then we should get optimal CPU and memory use, and minimal heap churn.
private static final DataSourceBean.AEPLinkedKey fullSearchCacheKey
| Constructor Detail |
|---|
public SearchResultSimpleCache()
| Method Detail |
|---|
private static int computeCacheMaxSize()
public java.util.List<Name.ExhibitFull> getRelatedExhibits(DataSourceBean dataSource,
Name.ExhibitFull exhibitFullName,
int maxResults)
throws java.io.IOException
The (immutable) results are limited to at most ABS_MAX_RESULTS items.
Excludes the exhibit itself and variants of the exhibit (same main words stem, etc, giving same canonicalised search term) on the assumption that they may already have been shown in other ways.
This allows potentially-redundant requests to execute in parallel at the risk of a little wasted work so as to maximise potential concurrency.
We do NOT cache any results if we don't believe the index to be up-to-date (eg to avoid cacheing stale/empty values).
java.io.IOExceptionpublic static Name computeRawSearchTermFromExhibitName(Name.ExhibitFull exhibitFullName)
This keeps the constituent words in the order supplied, and always retains the first word (later duplicates may be discarded for example) as earlier words are taken to be more important.
public static java.util.List<Name.ExhibitFull> doCachedCatPageSimilarItems(DataSourceBean dsb,
Name.ExhibitFull exhibitName,
int maxToShow)
public static java.util.concurrent.Future<java.util.List<Name.ExhibitFull>> doCachedCatPageSimilarItemsFuture(DataSourceBean dsb,
Name.ExhibitFull exhibitFullName,
int maxResults)
public static java.util.concurrent.Future<java.util.List<Name.ExhibitFull>> doCachedCatPageSimilarItemsFuture(DataSourceBean dsb,
Name.ExhibitFull exhibitFullName,
int maxResults,
boolean discardable)
discardable - if true then this call will never block but the request is discardable,
ie may never even be scheduled to run or may run at low priority,
or may immediately return a real result
or may immediately return an empty result if there seems no prospect of getting a task queued,
so code should not wait indefinitely for a task completion (eg with get()) that may never come
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||