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.
Solution: Generate the initial cache key with a mix of the wiki id located in the context and the XWikiDocument reference.
Otherwise not the same document is delivered in both possible situations.
1. from cache
2. freshly loaded