6

I am having an issue getting the DD4T DefaultCacheAgent to work. I am using Castle Windsor and have the DI setup like this.

container.Register(Component.For<ICacheAgent>().ImplementedBy<DefaultCacheAgent>().LifestyleTransient());

When setup like this it works. However, notice it is setup as "Transient". Transient seems to defeat the purpose of having a cache so I tried to make it Singleton. However, whenever I make it anything but transient I get this error:

GetLastPublishedDateCallBack called for unexpected object type 'DD4T.ContentModel.Component' or with unexpected key 'ComponentByUri_tcm:17-1721_'

It is as though it is trying to get something from the cache that it has not put in the cache yet but does not know any better.

Here is what is in the core log and the caching log.

Core

2014-09-02 16:46:58,713 DEBUG ComponentMetaFactory - Retrieved ComponentMeta instance: com.tridion.storage.mapper.ComponentMetaImpl@58b7d0f 2014-09-02 16:46:58,760 DEBUG MapperFactory - No data provided for mapping; mapping to empty custom meta 2014-09-02 16:46:59,353 DEBUG ComponentMetaFactory - Started Retrieving ComponentMeta instance 2014-09-02 16:46:59,353 DEBUG MapperFactory - No data provided for mapping; mapping to empty custom meta 2014-09-02 16:46:59,354 DEBUG ComponentMetaFactory - Retrieved ComponentMeta instance: com.tridion.storage.mapper.ComponentMetaImpl@8bf66a1 2014-09-02 16:46:59,619 DEBUG ComponentMetaFactory - Started Retrieving ComponentMeta instance 2014-09-02 16:46:59,619 DEBUG MapperFactory - No data provided for mapping; mapping to empty custom meta 2014-09-02 16:46:59,620 DEBUG ComponentMetaFactory - Retrieved ComponentMeta instance: com.tridion.storage.mapper.ComponentMetaImpl@4dead883 2014-09-02 16:46:59,727 DEBUG ComponentMetaFactory - Started Retrieving ComponentMeta instance 2014-09-02 16:46:59,727 DEBUG MapperFactory - No data provided for mapping; mapping to empty custom meta 2014-09-02 16:46:59,728 DEBUG ComponentMetaFactory - Retrieved ComponentMeta instance: com.tridion.storage.mapper.ComponentMetaImpl@752ca86b 2014-09-02 16:46:59,775 DEBUG MapperFactory - No data provided for mapping; mapping to empty custom meta

Caching

2014-09-02 16:46:51,321 DEBUG LRUPolicy - LRUModel: listSize = 52 memSize = 225230 2014-09-02 16:46:51,322 DEBUG CacheController - Adding a dependency from Object [17:1669] in Region [/com.tridion.storage.ItemMeta] to Object [17:1669:ComponentMeta:true] in Region [/com.tridion.storage.ItemMeta] 2014-09-02 16:46:51,445 DEBUG LRUPolicy - LRUModel: listSize = 53 memSize = 225828 2014-09-02 16:46:51,564 DEBUG LRUPolicy - LRUModel: listSize = 54 memSize = 226103 2014-09-02 16:46:51,564 DEBUG CacheController - Adding a dependency from Object [17:1646] in Region [/com_tridion_linking_ComponentLinkInfo] to Object [false:false:17:0:1646:0::] in Region [/com.tridion.linking.ComponentLink] 2014-09-02 16:46:51,565 DEBUG CacheController - Adding a dependency from Object [17:0] in Region [/com.tridion.broker.pages.meta.PageMeta] to Object [false:false:17:0:1646:0::] in Region [/com.tridion.linking.ComponentLink] 2014-09-02 16:51:36,710 INFO CacheFactory - No policy configured, creating a cache with an empty policy. 2014-09-02 16:51:36,711 INFO CacheFactory - No policy configured, creating a cache with an empty policy. 2014-09-02 16:53:41,975 INFO CacheFactory - No policy configured, creating a cache with an empty policy. 2014-09-02 16:53:41,977 INFO CacheFactory - No policy configured, creating a cache with an empty policy.

DD4T log

2014-09-02 16:57:16,366 [5] DEBUG Performance [(null)] - >>GetComponent (tcm:17-1721) 2014-09-02 16:57:16,368 [5] DEBUG Performance [(null)] - >>TryGetComponent (tcm:17-1721) 2014-09-02 16:57:16,372 [5] DEBUG Performance [(null)] - >>GetContent(tcm:17-1721) 2014-09-02 16:57:16,376 [5] DEBUG Performance [(null)] - GetContent: about to find all component presentations for tcm:17-1721 2014-09-02 16:57:16,881 [5] DEBUG Performance [(null)] - GetContent: found all component presentations for tcm:17-1721 2014-09-02 16:57:16,891 [5] DEBUG Performance [(null)] - <>LastPublishDateChangeMonitor(ComponentByUri_tcm:17-1721_, DD4T.ContentModel.Component) 2014-09-02 16:57:17,033 [5] DEBUG Performance [(null)] - >>GetLastPublishedDateCallBack ComponentByUri_tcm:17-1721_

7

The issue with trying to reuse a single ICacheAgent instance is that both the ComponentFactory and PageFactory classes override the GetLastPublishDateCallBack property, and both make assumptions about the type of cached objects they will handle. The ComponentFactory assumes that the cached objects will implement IComponent; the PageFactory assumes the cached objects will implement IPage. When the two factories share an ICacheAgent, they end up stepping on each other. In your scenario, the cache agent for the ComponentFactory is running the callback for the PageFactory.

Because of this, the ICacheAgent registration needs to be transient. The DefaultCacheAgent stores cached objects in the default MemoryCache instance, so there's no issue with creating many new DefaultCacheAgent instances---they'll all share the same underlying cache.

An alternative would be to create a callback that can handle both IPage and IComponent instances. You would need to create custom PageFactory and ComponentFactory classes, and override the GetLastPublishDateCallBack method in both to use your new, custom callback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.