private void initializeExtractedTextCache(BundleContext bundleContext, Map<String, ?> config) { int cacheSizeInMB = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_SIZE), PROP_EXTRACTED_TEXT_CACHE_SIZE_DEFAULT); int cacheExpiryInSecs = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_EXPIRY), PROP_EXTRACTED_TEXT_CACHE_EXPIRY_DEFAULT); boolean alwaysUsePreExtractedCache = PropertiesUtil.toBoolean(config.get(PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE), PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE_DEFAULT); extractedTextCache = new ExtractedTextCache( cacheSizeInMB * ONE_MB, cacheExpiryInSecs, alwaysUsePreExtractedCache, indexDir); if (extractedTextProvider != null){ registerExtractedTextProvider(extractedTextProvider); } CacheStats stats = extractedTextCache.getCacheStats(); if (stats != null){ oakRegs.add(registerMBean(whiteboard, CacheStatsMBean.class, stats, CacheStatsMBean.TYPE, stats.getName())); log.info("Extracted text caching enabled with maxSize {} MB, expiry time {} secs", cacheSizeInMB, cacheExpiryInSecs); } }
private void initializeExtractedTextCache(BundleContext bundleContext, Map<String, ?> config) { int cacheSizeInMB = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_SIZE), PROP_EXTRACTED_TEXT_CACHE_SIZE_DEFAULT); int cacheExpiryInSecs = PropertiesUtil.toInteger(config.get(PROP_EXTRACTED_TEXT_CACHE_EXPIRY), PROP_EXTRACTED_TEXT_CACHE_EXPIRY_DEFAULT); boolean alwaysUsePreExtractedCache = PropertiesUtil.toBoolean(config.get(PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE), PROP_PRE_EXTRACTED_TEXT_ALWAYS_USE_DEFAULT); extractedTextCache = new ExtractedTextCache( cacheSizeInMB * ONE_MB, cacheExpiryInSecs, alwaysUsePreExtractedCache, indexDir); if (extractedTextProvider != null){ registerExtractedTextProvider(extractedTextProvider); } CacheStats stats = extractedTextCache.getCacheStats(); if (stats != null){ oakRegs.add(registerMBean(whiteboard, CacheStatsMBean.class, stats, CacheStatsMBean.TYPE, stats.getName())); log.info("Extracted text caching enabled with maxSize {} MB, expiry time {} secs", cacheSizeInMB, cacheExpiryInSecs); } }
@Test public void cacheDisabling() throws Exception { ExtractedTextCache cache = new ExtractedTextCache(0, 0); assertNull(cache.getCacheStats()); }
@Test public void enableExtractedTextCaching() throws Exception{ Map<String,Object> config = getDefaultConfig(); config.put("extractedTextCacheSizeInMB", 11); MockOsgi.activate(service, context.bundleContext(), config); ExtractedTextCache textCache = service.getExtractedTextCache(); assertNotNull(textCache.getCacheStats()); assertNotNull(context.getService(CacheStatsMBean.class)); assertEquals(11 * FileUtils.ONE_MB, textCache.getCacheStats().getMaxTotalWeight()); MockOsgi.deactivate(service, context.bundleContext()); assertNull(context.getService(CacheStatsMBean.class)); }
@Test public void cacheEnabled() throws Exception { ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100); assertNotNull(cache.getCacheStats()); Blob b = new IdBlob("hello", "a"); String text = cache.get("/a", "foo", b, false); assertNull(text); cache.put(b, new ExtractedText(ExtractionResult.SUCCESS, "test hello")); text = cache.get("/a", "foo", b, false); assertEquals("test hello", text); }