/** * Gets all the properties for a given page id */ @SuppressWarnings("unchecked") public ImmutableMap<String, ImmutableList<ImmutableMap<String, PageProperty>>> get(final long pageId, Supplier<ImmutableMap<String, ImmutableList<ImmutableMap<String, PageProperty>>>> loader) { return join(cacheRef.get().get(Long.toString(pageId), loader)); }
private Void removeFromCache(String statusId) { return join(cacheRef.get().remove(statusId)); }
public void clearCache() { join(cacheRef.get().removeAll()); }
public String getEmbedData(String url, Pattern pattern, String cacheName) { final StableReadExternalCache<String> cache = getCache(cacheName); final Optional<String> result = join(cache.get(url)); if (result.isPresent()) return result.get(); HttpResponse response = getResponse(url); String line; try { if (response == null) return null; BufferedReader br = new BufferedReader(new InputStreamReader(response.getResponse())); Matcher m; while ((line = br.readLine()) != null) { m = pattern.matcher(line); if (m.find()) { br.close(); String embedId = m.group(1); join(getCache(cacheName).put(url, embedId, PUT_ALWAYS)); return embedId; } } br.close(); } catch (IOException e) { log.error("An error occured parsing the response from: " + url); } finally { if (response != null) response.finish(); } return null; }
@Nonnull private TweetRetrievalResult getTweetRetrievalResultFromCache(String statusId, Supplier<TweetRetrievalResult> loader) { try { final TweetRetrievalResult result = join(cacheRef.get().get(statusId, loader::get)); if (result.isExpiredFailureResult()) // The cache contains a failure result that has now expired, so remove it removeFromCache(statusId); return result; } catch (ClassCastException | VCacheException pluginUpgraded) { LOG.debug("Removed cached Tweet retrieval result by a previously installed version of the Widget Connector Plugin.", pluginUpgraded); removeFromCache(statusId); return loader.get(); } }
private void invalidateCacheOnContentEvent(final Object event) { if (event instanceof Contented) join(cacheRef.get().remove(((Contented)event).getContent().getIdAsString())); }