/** * Add a descriptor to the cache. * * @param wikiAlias Alias of the wiki to get * @param descriptor descriptor to add */ public void addFromAlias(String wikiAlias, DefaultWikiDescriptor descriptor) { this.wikiAliasCache.set(wikiAlias, descriptor); }
/** * Add a descriptor to the cache. * * @param wikiId Id of the wiki to get * @param descriptor descriptor to add */ public void addFromId(String wikiId, DefaultWikiDescriptor descriptor) { this.wikiIdCache.set(wikiId, descriptor); }
public void putInCache(String key, Object obj) { this.cache.set(key, obj); }
@Override public void put(DocumentReference documentReference, IconSet iconSet) { cache.set(getKeyFromDocument(documentReference), iconSet); }
@Override public void put(String name, IconSet iconSet) { cache.set(getKeyFromName(name), iconSet); }
@Override public void set(String fileName, String wiki, String fileSystemSkin, String colorTheme, T content) { // Store the content in the cache String cacheKey = getCacheKey(fileName, wiki, fileSystemSkin, colorTheme); cache.set(cacheKey, content); // Add the new key to cachedFilesKeysMap. List<String> cachedFilesKeys = cachedFilesKeysMap.get(wiki); if (cachedFilesKeys == null) { // if the list of cached files keys corresponding to the wiki does not exist, we create it cachedFilesKeys = new ArrayList<>(); cachedFilesKeysMap.put(wiki, cachedFilesKeys); } if (!cachedFilesKeys.contains(cacheKey)) { cachedFilesKeys.add(cacheKey); } }
private JSONObject getInfo() { JSONObject info = this.infoCache.get(""); if (info != null) { return info; } HttpGet method = new HttpGet(this.infoServiceURL); method.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()); try (CloseableHttpResponse httpResponse = this.client.execute(method)) { String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8); JSONObject responseJSON = new JSONObject(response); this.infoCache.set("", responseJSON); return responseJSON; } catch (IOException | JSONException ex) { this.logger.warn("Failed to get HGNC information: {}", ex.getMessage()); } return null; }
/** * {@inheritDoc} * * @see com.xpn.xwiki.internal.cache.DocumentCache#set(java.lang.Object, * org.xwiki.model.reference.DocumentReference, java.lang.Object[]) */ public void set(C data, DocumentReference documentReference, Object... extensions) { String key = getKey(documentReference, extensions); this.cache.set(key, data); String documentReferenceString = this.serializer.serialize(documentReference); Collection<String> keys = this.mappingCache.get(documentReferenceString); if (keys == null) { keys = new HashSet<String>(); this.mappingCache.set(documentReferenceString, keys); } keys.add(key); }
private VocabularyTerm cacheTerm(String id, SolrDocument doc) { Cache<VocabularyTerm> cache = this.externalServicesAccess.getTermCache(this); VocabularyTerm term = cache.get(id); if (term == null) { term = new SolrVocabularyTerm(doc, this); cache.set(id, term); } return term; } }
public SyndFeed getFeed(String sfeed, boolean ignoreInvalidFeeds, boolean force, XWikiContext context) throws IOException { SyndFeed feed = null; prepareCache(context); if (!force) { feed = this.feedCache.get(sfeed); } if (feed == null) { feed = getFeedForce(sfeed, ignoreInvalidFeeds, context); } if (feed != null) { this.feedCache.set(sfeed, feed); } return feed; }
@Override public Set<NotificationFilterPreference> getFilterPreferences(DocumentReference user) throws NotificationException { if (user == null) { return Collections.EMPTY_SET; } String userId = serializer.serialize(user); Set<NotificationFilterPreference> preferences = cache.get(userId); if (preferences != null) { return preferences; } preferences = modelBridge.getFilterPreferences(user); cache.set(userId, preferences); return preferences; }
@Override public void set(LESSResourceReference lessResourceReference, SkinReference skin, ColorThemeReference colorTheme, T content) { // Store the content in the cache String cacheKey = cacheKeyFactory.getCacheKey(lessResourceReference, skin, colorTheme, isContextHandled); cache.set(cacheKey, content); // Add the new key to maps registerCacheKey(cachedFilesKeysMapPerSkin, cacheKey, skin); registerCacheKey(cachedFilesKeysMapPerColorTheme, cacheKey, colorTheme); registerCacheKey(cachedFilesKeysMapPerLESSResource, cacheKey, lessResourceReference); }
/** * Returns the session storage allocated for the current user. * * @return Session storage. */ public XWikiDavUserStorage getUserStorage() { String user = xwikiContext.getUser(); if (null == davCache.get(user)) { davCache.set(user, new XWikiDavUserStorage()); } return davCache.get(user); }
public boolean exists(XWikiDocument doc, XWikiContext context) throws XWikiException { String key = getKey(doc, context); initCache(context); try { Boolean result = getPageExistCache().get(key); if (result != null) { return result; } } catch (Exception e) { } boolean result = this.store.exists(doc, context); getPageExistCache().set(key, new Boolean(result)); return result; }
/** * Get non-component bundle. */ private TranslationBundle getOnDemandDocumentBundle(DocumentReference documentReference) throws TranslationBundleDoesNotExistsException { String uid = this.uidSerializer.serialize(documentReference); TranslationBundle bundle = this.onDemandBundleCache.get(uid); if (bundle == null) { synchronized (this.onDemandBundleCache) { bundle = this.onDemandBundleCache.get(uid); if (bundle == null) { bundle = createOnDemandDocumentBundle(documentReference, uid); this.onDemandBundleCache.set(uid, bundle); } } } return bundle; }
public void deleteXWikiDoc(XWikiDocument doc, XWikiContext context) throws XWikiException { String key = getKey(doc, context); this.store.deleteXWikiDoc(doc, context); // Make sure cache is initialized initCache(context); getCache().remove(key); getPageExistCache().remove(key); getPageExistCache().set(key, new Boolean(false)); }
@Override public VocabularyTerm getTerm(String id) { if (StringUtils.isBlank(id)) { return null; } VocabularyTerm result = this.externalServicesAccess.getTermCache(this).get(id); if (result == null) { SolrQuery query = new SolrQuery(ID_FIELD_NAME + ':' + ClientUtils.escapeQueryChars(id)); SolrDocumentList allResults = this.search(query); if (allResults != null && !allResults.isEmpty()) { result = new SolrVocabularyTerm(allResults.get(0), this); this.externalServicesAccess.getTermCache(this).set(id, result); } else { this.externalServicesAccess.getTermCache(this).set(id, EMPTY_MARKER); } } return (result == EMPTY_MARKER) ? null : result; }
@Override public OntologyTerm getTerm(String id) { OntologyTerm result = this.externalServicesAccess.getCache().get(id); if (result == null) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CommonParams.Q, ID_FIELD_NAME + ':' + ClientUtils.escapeQueryChars(id)); SolrDocumentList allResults = this.search(params); if (allResults != null && !allResults.isEmpty()) { result = new SolrOntologyTerm(allResults.get(0), this); this.externalServicesAccess.getCache().set(id, result); } else { this.externalServicesAccess.getCache().set(id, EMPTY_MARKER); } } return (result == EMPTY_MARKER) ? null : result; }
public Object parseGroovyFromString(String script, XWikiContext context) throws XWikiException { prepareCache(context); ClassLoader parentClassLoader = (ClassLoader) context.get("parentclassloader"); try { CachedGroovyClass cgc = this.classCache.get(script); Class< ? > gc; if (cgc == null) { GroovyClassLoader gcl = (parentClassLoader == null) ? new GroovyClassLoader() : new GroovyClassLoader(parentClassLoader); gc = gcl.parseClass(script); cgc = new CachedGroovyClass(gc); this.classCache.set(script, cgc); } else { gc = cgc.getGroovyClass(); } return gc.newInstance(); } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_GROOVY, XWikiException.ERROR_XWIKI_GROOVY_COMPILE_FAILED, "Failed compiling groovy script", e); } }
private OfficeDocumentView getView(ResourceReference resourceReference, Map<String, ?> parameters) throws Exception { DocumentReference ownerDocument = getOwnerDocument(parameters); String serializedResourceReference = this.resourceReferenceSerializer.serialize(resourceReference); // Search the cache. String cacheKey = getCacheKey(ownerDocument, serializedResourceReference, parameters); OfficeDocumentView view = this.externalCache.get(cacheKey); // If a view in not available, build one and cache it. if (view == null) { XDOMOfficeDocument xdomOfficeDocument = createXDOM(ownerDocument, resourceReference, parameters); XDOM xdom = xdomOfficeDocument.getContentDocument(); Set<File> temporaryFiles = processImages(xdom, xdomOfficeDocument.getArtifacts(), ownerDocument, serializedResourceReference, parameters); view = new OfficeDocumentView(resourceReference, xdom, temporaryFiles); this.externalCache.set(cacheKey, view); } return view; }