The DD4T object cache by default checks for the last publish date of the underlying Tridion components and pages. The problem with Session Preview in Experience Manager is that it does not change the last publish date. This can cause your web application to cache the temporary content created during an XPM session, and use that even after the XPM session has been closed.
The easiest solution would be to use DD4T's NullCacheAgent instead of the DefaultCacheAgent. This can be done by setting the CacheAgent property on the PageFactory and ComponentFactory in your controller. You could for example put the following code in your page controller:
private IPageFactory _pageFactory = null;
public override ContentModel.Factories.IPageFactory PageFactory
{
get
{
if (_pageFactory == null)
{
_pageFactory = base.PageFactory;
_pageFactory.CacheAgent = new DD4T.Factories.Caching.NullCacheAgent();
}
return _pageFactory;
}
}
Alternative solution
You could also disable caching per item type, for example for components only. This can be done by putting the following line in the appSettings section of the web.config:
<add key="DD4T.CacheSettings.Component" value="0" />
This way, pages and things like sitemaps are still cached, improving the performance of your staging environment.
In the live production environment you should turn on caching.