Problem: if you request an unpublished DCP, the 'null result' is cached. If you then (re)publish the item, the null result is not invalidated, so you will not see the new item even though it is available in the broker. Restarting the web application solves this, but that is not what you want to do.
Solution: I don't see a reason why we shouldn't cache the null result with the same dependencies. The advantage that the CP Factory has, is that the unique ID of the item is known before it is retrieved. The same information is broadcast by the JMS service so it can be used to invalidate the null item in the cache. Is there ever a reason why you wouldn't want to retrieve a DCP when it is published?
As far as I'm concerned we can simply change line 111 into:
Problem: if you request an unpublished DCP, the 'null result' is cached. If you then (re)publish the item, the null result is not invalidated, so you will not see the new item even though it is available in the broker. Restarting the web application solves this, but that is not what you want to do.
Root cause: the factory class (ComponentPresentationFactoryImpl) caches a null result without a dependency on the ID of the component and publication (see https://github.com/dd4t/dd4t-2-java/blob/develop/dd4t-core/src/main/java/org/dd4t/core/factories/impl/ComponentPresentationFactoryImpl.java line 111), while a DCP that is actually retrieved (non-null) is cached WITH these dependencies (line 127).
Solution: I don't see a reason why we shouldn't cache the null result with the same dependencies. The advantage that the CP Factory has, is that the unique ID of the item is known before it is retrieved. The same information is broadcast by the JMS service so it can be used to invalidate the null item in the cache. Is there ever a reason why you wouldn't want to retrieve a DCP when it is published? As far as I'm concerned we can simply change line 111 into:
cacheProvider.storeInItemCache(key, cacheElement, publicationId, componentId);