Package com.norconex.importer.handler
Interface DocHandlerCache
- All Known Implementing Classes:
ClusterDocHandlerCache
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A key/value cache made available to document handlers for results that are
expensive or costly to obtain more than once for the same input (e.g., a
call to a paid external API). The importer itself does not implement one:
whatever runs it (a crawler, the command-line launcher, a test) may supply
one via DocHandlerContext, so it can back it with whatever storage
makes sense there — a crawler backs it with its own persistent, cluster-
aware store, at no extra cost to a handler that uses it.
A handler is never left checking for null: when nothing is
supplied, DocHandlerContext falls back to NOOP, which
always calls the DocHandlerCache.Loader and never remembers the result.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceComputes a value to be cached, for whichever key was not already in the cache. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DocHandlerCacheA cache that holds nothing: every lookup is a miss, so theDocHandlerCache.Loaderalways runs. -
Method Summary
Modifier and TypeMethodDescriptioncomputeIfAbsent(String key, DocHandlerCache.Loader loader) Returns the value previously cached forkey, or computes it withloader, caches it, then returns it.
-
Field Details
-
NOOP
A cache that holds nothing: every lookup is a miss, so theDocHandlerCache.Loaderalways runs. Used whenever no real cache is supplied.
-
-
Method Details
-
computeIfAbsent
Returns the value previously cached forkey, or computes it withloader, caches it, then returns it.- Parameters:
key- cache keyloader- supplies the value when not already cached- Returns:
- the cached or freshly computed value
- Throws:
IOException- if the loader fails to compute a value
-