XWikiCacheStore#loadXWikiDoc is actually a bit tricker than that right now for retro compatibility and laziness (really need to rewrite this whole store API) reasons and before applying what you propose the way it deals with document uid should be modified a bit.
Hibernate store is always loading the document from the wiki indicated in the context completely ignoring the wiki in the XWikiDocument object. That means that doc.getKey() may be different than the key of the document that will actually come from the hibernate store. So before adding DocumentLoader jingling a first thing to do is generate the initial cache key with a mix of the wiki id located in the context and the XWikiDocument reference. Then what you propose sounds good. On Mon, Aug 8, 2016 at 8:53 AM, Fabian Pichler <[email protected]> wrote: > Hi devs > > http://jira.xwiki.org/browse/XWIKI-13623 > I would like to discuss the suggested solution, before I start implementing > it: > > *I suggest the following solution:* > Introducing a nested DocumentLoader class which loads the document calling > the basestore loadXWikiDoc in a synchronized getDocOrLoad method. The > DocumentLoader objects gets instantiated in the cacheStore on a cache miss. > It then gets stored in a ConcurrentHashMap using the same key which is used > for the document cache (DocumentReference including language). Using > putIfAbsent to insert the DocumentLoader and calling the synchronized load > method on the object in the map solves the memory visibility issue and > moreover ensures that the same XWikiDocument is not loaded multiple times > concurrently from the database. It is still possible to load different > documents in parallel. A DocumentLoader will load the XWikiDocument only > once and the returns the identical document object on any following call of > the synchronized getDocOrLoad method. > > WDYT? > > Kind Regards, > Fabian > _______________________________________________ > devs mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/devs -- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

