@Test void loadXWikiDoc() throws Exception { this.oldcore.getXWikiContext().setWikiId("wiki"); this.oldcore.getSpyXWiki().saveDocument(new XWikiDocument(new DocumentReference("wiki", "space", "page")), this.oldcore.getXWikiContext()); DocumentReference reference = new DocumentReference("otherwiki", "space", "page"); XWikiCacheStore store = new XWikiCacheStore(this.oldcore.getMockStore(), this.oldcore.getXWikiContext()); XWikiDocument existingDocument = store.loadXWikiDoc(new XWikiDocument(reference), this.oldcore.getXWikiContext()); assertFalse(existingDocument.isNew()); verify(this.cache).set(eq("4:wiki5:space4:page0:"), any(XWikiDocument.class)); verify(this.existCache).set("4:wiki5:space4:page0:", Boolean.TRUE); verify(this.cache).get(any()); verify(this.existCache).get(any()); verifyNoMoreInteractions(this.cache); verifyNoMoreInteractions(this.existCache); XWikiDocument notExistingDocument = store.loadXWikiDoc(new XWikiDocument(new DocumentReference("otherwiki", "space", "nopage")), this.oldcore.getXWikiContext()); assertTrue(notExistingDocument.isNew()); verify(this.cache).set(eq("4:wiki5:space4:page0:"), any(XWikiDocument.class)); verify(this.existCache).set("4:wiki5:space4:page0:", Boolean.TRUE); verify(this.existCache).set("4:wiki5:space6:nopage0:", Boolean.FALSE); verify(this.cache, times(2)).get(any()); verify(this.existCache, times(2)).get(any()); verifyNoMoreInteractions(this.cache); verifyNoMoreInteractions(this.existCache); }
@Override public XWikiDocument loadXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext) throws XWikiException { XWikiContext context = getExecutionXContext(inputxcontext, true); try { String key = getKey(doc, context); LOGGER.debug("Cache: Trying to get doc {} from cache", key); XWikiDocument cachedoc; try { cachedoc = getCache().get(key); } catch (Exception e) { LOGGER.error("Failed to get document from the cache", e); cachedoc = null; } if (cachedoc != null) { cachedoc.setFromCache(true); LOGGER.debug("Cache: got doc {} from cache", key); } else { Boolean result = getPageExistCache().get(key); if (result == Boolean.FALSE) { LOGGER.debug("Cache: The document {} does not exist, return an empty one", key); cachedoc = doc; cachedoc.setNew(true); cachedoc .setOriginalDocument(new XWikiDocument(cachedoc.getDocumentReference(), cachedoc.getLocale())); } else { LOGGER.debug("Cache: Trying to get doc {} from persistent storage", key); cachedoc = this.store.loadXWikiDoc(doc, context); LOGGER.debug("Cache: Got doc {} from storage", key); if (cachedoc.isNew()) { getPageExistCache().set(key, Boolean.FALSE); } else { getCache().set(key, cachedoc); getPageExistCache().set(key, Boolean.TRUE); } LOGGER.debug("Cache: put doc {} in cache", key); } } cachedoc.setStore(this); LOGGER.debug("Cache: end for doc {} in cache", key); return cachedoc; } finally { restoreExecutionXContext(); } }
XWikiCacheStore extends AbstractXWikiStore implements XWikiCacheStoreInterface, EventListener, Initializable { @Override public XWikiDocument loadXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext) throws XWikiException { XWikiContext context = getExecutionXContext(inputxcontext, true); try { String key = getKey(doc, context); LOGGER.debug("Cache: Trying to get doc {} from cache", key); XWikiDocument cachedoc; try { cachedoc = getCache().get(key); } catch (Exception e) { LOGGER.error("Failed to get document from the cache", e); cachedoc = null; } if (cachedoc != null) { cachedoc.setFromCache(true); LOGGER.debug("Cache: got doc {} from cache", key); } else { Boolean result = getPageExistCache().get(key); if (result == Boolean.FALSE) { LOGGER.debug("Cache: The document {} does not exist, return an empty one", key); cachedoc = doc; cachedoc.setNew(true); cachedoc .setOriginalDocument(new XWikiDocument(cachedoc.getDocumentReference(), cachedoc.getLocale())); } else { LOGGER.debug("Cache: Trying to get doc {} from persistent storage", key); cachedoc = this.store.loadXWikiDoc(doc, context); LOGGER.debug("Cache: Got doc {} from storage", key); if (cachedoc.isNew()) { getPageExistCache().set(key, Boolean.FALSE); } else { getCache().set(key, cachedoc); getPageExistCache().set(key, Boolean.TRUE); } LOGGER.debug("Cache: put doc {} in cache", key); } } cachedoc.setStore(this); LOGGER.debug("Cache: end for doc {} in cache", key); return cachedoc; } finally { restoreExecutionXContext(); } } }
XWikiCacheStore extends AbstractXWikiStore implements XWikiCacheStoreInterface, EventListener, Initializable { @Override public XWikiDocument loadXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext) throws XWikiException { XWikiContext context = getExecutionXContext(inputxcontext, true); try { String key = getKey(doc, context); LOGGER.debug("Cache: Trying to get doc {} from cache", key); XWikiDocument cachedoc; try { cachedoc = getCache().get(key); } catch (Exception e) { LOGGER.error("Failed to get document from the cache", e); cachedoc = null; } if (cachedoc != null) { cachedoc.setFromCache(true); LOGGER.debug("Cache: got doc {} from cache", key); } else { Boolean result = getPageExistCache().get(key); if (result == Boolean.FALSE) { LOGGER.debug("Cache: The document {} does not exist, return an empty one", key); cachedoc = doc; cachedoc.setNew(true); cachedoc .setOriginalDocument(new XWikiDocument(cachedoc.getDocumentReference(), cachedoc.getLocale())); } else { LOGGER.debug("Cache: Trying to get doc {} from persistent storage", key); cachedoc = this.store.loadXWikiDoc(doc, context); LOGGER.debug("Cache: Got doc {} from storage", key); if (cachedoc.isNew()) { getPageExistCache().set(key, Boolean.FALSE); } else { getCache().set(key, cachedoc); getPageExistCache().set(key, Boolean.TRUE); } LOGGER.debug("Cache: put doc {} in cache", key); } } cachedoc.setStore(this); LOGGER.debug("Cache: end for doc {} in cache", key); return cachedoc; } finally { restoreExecutionXContext(); } } XWikiCacheStore();  XWikiCacheStore(XWikiStoreInterface store, XWikiContext context); }
XWikiCacheStore extends AbstractXWikiStore implements XWikiCacheStoreInterface, EventListener, Initializable { @Override public XWikiDocument loadXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext) throws XWikiException { XWikiContext context = getExecutionXContext(inputxcontext, true); try { String key = getKey(doc, context); LOGGER.debug("Cache: Trying to get doc {} from cache", key); XWikiDocument cachedoc; try { cachedoc = getCache().get(key); } catch (Exception e) { LOGGER.error("Failed to get document from the cache", e); cachedoc = null; } if (cachedoc != null) { cachedoc.setFromCache(true); LOGGER.debug("Cache: got doc {} from cache", key); } else { Boolean result = getPageExistCache().get(key); if (result == Boolean.FALSE) { LOGGER.debug("Cache: The document {} does not exist, return an empty one", key); cachedoc = doc; cachedoc.setNew(true); cachedoc .setOriginalDocument(new XWikiDocument(cachedoc.getDocumentReference(), cachedoc.getLocale())); } else { LOGGER.debug("Cache: Trying to get doc {} from persistent storage", key); cachedoc = this.store.loadXWikiDoc(doc, context); LOGGER.debug("Cache: Got doc {} from storage", key); if (cachedoc.isNew()) { getPageExistCache().set(key, Boolean.FALSE); } else { getCache().set(key, cachedoc); getPageExistCache().set(key, Boolean.TRUE); } LOGGER.debug("Cache: put doc {} in cache", key); } } cachedoc.setStore(this); LOGGER.debug("Cache: end for doc {} in cache", key); return cachedoc; } finally { restoreExecutionXContext(); } } XWikiCacheStore();  XWikiCacheStore(XWikiStoreInterface store, XWikiContext context); @Override void initialize(); @Override String getName(); @Override List<Event> getEvents(); @Deprecated void initCache(XWikiContext context); @Deprecated @Override void initCache(int capacity, int pageExistCacheCapacity, XWikiContext context); @Override XWikiStoreInterface getStore(); @Override void setStore(XWikiStoreInterface store); @Override void saveXWikiDoc(XWikiDocument doc, XWikiContext context); @Override void renameXWikiDoc(XWikiDocument doc, DocumentReference newReference, XWikiContext inputxcontext); @Override void saveXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext, boolean bTransaction); @Override void flushCache(); @Override void onEvent(Event event, Object source, Object data); @Deprecated String getKey(XWikiDocument doc); String getKey(XWikiDocument doc, XWikiContext context); @Deprecated String getKey(String fullName, String language, XWikiContext context); @Deprecated String getKey(final String wiki, final String fullName, final String language); @Override XWikiDocument loadXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext); @Override void deleteXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext); @Override List<String> getClassList(XWikiContext context); @Override int countDocuments(String wheresql, XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String wheresql, XWikiContext context); @Override List<String> searchDocumentsNames(String wheresql, XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String wheresql, int nb, int start, XWikiContext context); @Override List<String> searchDocumentsNames(String wheresql, int nb, int start, XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String wheresql, int nb, int start, String selectColumns,
        XWikiContext context); @Override List<String> searchDocumentsNames(String wheresql, int nb, int start, String selectColumns,
        XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String parametrizedSqlClause, int nb, int start,
        List<?> parameterValues, XWikiContext context); @Override List<String> searchDocumentsNames(String parametrizedSqlClause, int nb, int start, List<?> parameterValues,
        XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String parametrizedSqlClause, List<?> parameterValues,
        XWikiContext context); @Override List<String> searchDocumentsNames(String parametrizedSqlClause, List<?> parameterValues,
        XWikiContext context); @Override boolean isCustomMappingValid(BaseClass bclass, String custommapping1, XWikiContext context); @Override boolean injectCustomMapping(BaseClass doc1class, XWikiContext context); @Override boolean injectCustomMappings(XWikiDocument doc, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, boolean customMapping,
        XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, int nb, int start,
        XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, boolean customMapping, int nb,
        int start, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, int nb, int start, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, boolean customMapping,
        boolean checkRight, int nb, int start, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbylanguage, int nb, int start,
        List<?> parameterValues, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, List<?> parameterValues, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbylanguage, boolean customMapping,
        int nb, int start, List<?> parameterValues, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, int nb, int start, List<?> parameterValues,
        XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbylanguage, boolean customMapping,
        boolean checkRight, int nb, int start, List<?> parameterValues, XWikiContext context); @Override int countDocuments(String parametrizedSqlClause, List<?> parameterValues, XWikiContext context); @Override XWikiLock loadLock(long docId, XWikiContext context, boolean bTransaction); @Override void saveLock(XWikiLock lock, XWikiContext context, boolean bTransaction); @Override void deleteLock(XWikiLock lock, XWikiContext context, boolean bTransaction); @Override List<XWikiLink> loadLinks(long docId, XWikiContext context, boolean bTransaction); @Override List<DocumentReference> loadBacklinks(DocumentReference documentReference, boolean bTransaction,
        XWikiContext context); @Override List<String> loadBacklinks(String fullName, XWikiContext context, boolean bTransaction); @Override void saveLinks(XWikiDocument doc, XWikiContext context, boolean bTransaction); @Override void deleteLinks(long docId, XWikiContext context, boolean bTransaction); @Override List<T> search(String sql, int nb, int start, XWikiContext context); @Override List<T> search(String sql, int nb, int start, Object[][] whereParams, XWikiContext context); @Override List<T> search(String sql, int nb, int start, List<?> parameterValues, XWikiContext context); @Override List<T> search(String sql, int nb, int start, Object[][] whereParams, List<?> parameterValues,
        XWikiContext context); @Override synchronized void cleanUp(XWikiContext context); @Override boolean isWikiNameAvailable(String wikiName, XWikiContext context); @Override void createWiki(String wikiName, XWikiContext context); @Override void deleteWiki(String wikiName, XWikiContext context); @Override boolean exists(XWikiDocument doc, XWikiContext inputxcontext); Cache<XWikiDocument> getCache(); void setCache(Cache<XWikiDocument> cache); Cache<Boolean> getPageExistCache(); void setPageExistCache(Cache<Boolean> pageExistCache); @Unstable Cache<Integer> getLimitSizePropertyCache(); @Override List<String> getCustomMappingPropertyList(BaseClass bclass); @Override synchronized void injectCustomMappings(XWikiContext context); @Override void injectUpdatedCustomMappings(XWikiContext context); @Override List<String> getTranslationList(XWikiDocument doc, XWikiContext context); @Override QueryManager getQueryManager(); @Override int getLimitSize(XWikiContext context, Class<?> entityType, String propertyName); }
XWikiCacheStore extends AbstractXWikiStore implements XWikiCacheStoreInterface, EventListener, Initializable { @Override public XWikiDocument loadXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext) throws XWikiException { XWikiContext context = getExecutionXContext(inputxcontext, true); try { String key = getKey(doc, context); LOGGER.debug("Cache: Trying to get doc {} from cache", key); XWikiDocument cachedoc; try { cachedoc = getCache().get(key); } catch (Exception e) { LOGGER.error("Failed to get document from the cache", e); cachedoc = null; } if (cachedoc != null) { cachedoc.setFromCache(true); LOGGER.debug("Cache: got doc {} from cache", key); } else { Boolean result = getPageExistCache().get(key); if (result == Boolean.FALSE) { LOGGER.debug("Cache: The document {} does not exist, return an empty one", key); cachedoc = doc; cachedoc.setNew(true); cachedoc .setOriginalDocument(new XWikiDocument(cachedoc.getDocumentReference(), cachedoc.getLocale())); } else { LOGGER.debug("Cache: Trying to get doc {} from persistent storage", key); cachedoc = this.store.loadXWikiDoc(doc, context); LOGGER.debug("Cache: Got doc {} from storage", key); if (cachedoc.isNew()) { getPageExistCache().set(key, Boolean.FALSE); } else { getCache().set(key, cachedoc); getPageExistCache().set(key, Boolean.TRUE); } LOGGER.debug("Cache: put doc {} in cache", key); } } cachedoc.setStore(this); LOGGER.debug("Cache: end for doc {} in cache", key); return cachedoc; } finally { restoreExecutionXContext(); } } XWikiCacheStore();  XWikiCacheStore(XWikiStoreInterface store, XWikiContext context); @Override void initialize(); @Override String getName(); @Override List<Event> getEvents(); @Deprecated void initCache(XWikiContext context); @Deprecated @Override void initCache(int capacity, int pageExistCacheCapacity, XWikiContext context); @Override XWikiStoreInterface getStore(); @Override void setStore(XWikiStoreInterface store); @Override void saveXWikiDoc(XWikiDocument doc, XWikiContext context); @Override void renameXWikiDoc(XWikiDocument doc, DocumentReference newReference, XWikiContext inputxcontext); @Override void saveXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext, boolean bTransaction); @Override void flushCache(); @Override void onEvent(Event event, Object source, Object data); @Deprecated String getKey(XWikiDocument doc); String getKey(XWikiDocument doc, XWikiContext context); @Deprecated String getKey(String fullName, String language, XWikiContext context); @Deprecated String getKey(final String wiki, final String fullName, final String language); @Override XWikiDocument loadXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext); @Override void deleteXWikiDoc(XWikiDocument doc, XWikiContext inputxcontext); @Override List<String> getClassList(XWikiContext context); @Override int countDocuments(String wheresql, XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String wheresql, XWikiContext context); @Override List<String> searchDocumentsNames(String wheresql, XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String wheresql, int nb, int start, XWikiContext context); @Override List<String> searchDocumentsNames(String wheresql, int nb, int start, XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String wheresql, int nb, int start, String selectColumns,
        XWikiContext context); @Override List<String> searchDocumentsNames(String wheresql, int nb, int start, String selectColumns,
        XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String parametrizedSqlClause, int nb, int start,
        List<?> parameterValues, XWikiContext context); @Override List<String> searchDocumentsNames(String parametrizedSqlClause, int nb, int start, List<?> parameterValues,
        XWikiContext context); @Override List<DocumentReference> searchDocumentReferences(String parametrizedSqlClause, List<?> parameterValues,
        XWikiContext context); @Override List<String> searchDocumentsNames(String parametrizedSqlClause, List<?> parameterValues,
        XWikiContext context); @Override boolean isCustomMappingValid(BaseClass bclass, String custommapping1, XWikiContext context); @Override boolean injectCustomMapping(BaseClass doc1class, XWikiContext context); @Override boolean injectCustomMappings(XWikiDocument doc, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, boolean customMapping,
        XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, int nb, int start,
        XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, boolean customMapping, int nb,
        int start, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, int nb, int start, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbyname, boolean customMapping,
        boolean checkRight, int nb, int start, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbylanguage, int nb, int start,
        List<?> parameterValues, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, List<?> parameterValues, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbylanguage, boolean customMapping,
        int nb, int start, List<?> parameterValues, XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, int nb, int start, List<?> parameterValues,
        XWikiContext context); @Override List<XWikiDocument> searchDocuments(String wheresql, boolean distinctbylanguage, boolean customMapping,
        boolean checkRight, int nb, int start, List<?> parameterValues, XWikiContext context); @Override int countDocuments(String parametrizedSqlClause, List<?> parameterValues, XWikiContext context); @Override XWikiLock loadLock(long docId, XWikiContext context, boolean bTransaction); @Override void saveLock(XWikiLock lock, XWikiContext context, boolean bTransaction); @Override void deleteLock(XWikiLock lock, XWikiContext context, boolean bTransaction); @Override List<XWikiLink> loadLinks(long docId, XWikiContext context, boolean bTransaction); @Override List<DocumentReference> loadBacklinks(DocumentReference documentReference, boolean bTransaction,
        XWikiContext context); @Override List<String> loadBacklinks(String fullName, XWikiContext context, boolean bTransaction); @Override void saveLinks(XWikiDocument doc, XWikiContext context, boolean bTransaction); @Override void deleteLinks(long docId, XWikiContext context, boolean bTransaction); @Override List<T> search(String sql, int nb, int start, XWikiContext context); @Override List<T> search(String sql, int nb, int start, Object[][] whereParams, XWikiContext context); @Override List<T> search(String sql, int nb, int start, List<?> parameterValues, XWikiContext context); @Override List<T> search(String sql, int nb, int start, Object[][] whereParams, List<?> parameterValues,
        XWikiContext context); @Override synchronized void cleanUp(XWikiContext context); @Override boolean isWikiNameAvailable(String wikiName, XWikiContext context); @Override void createWiki(String wikiName, XWikiContext context); @Override void deleteWiki(String wikiName, XWikiContext context); @Override boolean exists(XWikiDocument doc, XWikiContext inputxcontext); Cache<XWikiDocument> getCache(); void setCache(Cache<XWikiDocument> cache); Cache<Boolean> getPageExistCache(); void setPageExistCache(Cache<Boolean> pageExistCache); @Unstable Cache<Integer> getLimitSizePropertyCache(); @Override List<String> getCustomMappingPropertyList(BaseClass bclass); @Override synchronized void injectCustomMappings(XWikiContext context); @Override void injectUpdatedCustomMappings(XWikiContext context); @Override List<String> getTranslationList(XWikiDocument doc, XWikiContext context); @Override QueryManager getQueryManager(); @Override int getLimitSize(XWikiContext context, Class<?> entityType, String propertyName);  }