Problems getting caching working ...

Aug 29 at 3:17 PM
First of all, thanks for providing this functionality, and posting it out to Codeplex. I am having a problem getting the caching to actually work, and hopefully I am not missing something at the most fundamental level of how the library is supposed to work. I have created a Configuration.cs class out in my DAL library project as follows:
public class Configuration : DbConfiguration
    {

        public Configuration()
        {
            var transactionHandler = new CacheTransactionHandler(new InMemoryCache());

            AddInterceptor(transactionHandler);
            var cachingPolicy = new DataAccessLayer.DefaultCachingPolicy();

            Loaded +=
              (sender, args) => args.ReplaceService<DbProviderServices>(
                (s, _) => new CachingProviderServices(s, transactionHandler, cachingPolicy));
        }
    }
I put break points and I see the class getting called when my ASP.NET website starts up. I hooked up SQL profiler and noticed the same sql query being executed by Entity Framework multiple times for the same postback.

I thought I may have been missing something, so I went ahead and tried using the asp.net cache (written by emilm (https://efcache.codeplex.com/discussions/539904), added break points to all methods and ran again. The only break point that ever gets hit is InvalidateSets(). The GetItem() and PutItem() are not called. Shouldn't every query I send through Entity Framework be cached with the DefaultCachingPolicy as you have written it?
Coordinator
Aug 29 at 5:06 PM
Please provide a minimal functional repro. Without seeing the query it's hard to tell why the results are not being cached. If the query contains a function with side effects it won't be cached since the result would be different each time.

Thanks,
Pawel
Aug 29 at 10:27 PM
Edited Aug 29 at 10:27 PM
Thanks for the reply. I have uploaded a simple sample trying to use it on a ASP.NET webforms application on the Northwind database. See the zip here for the VS2013 solution.

Unfortunately, with the simple example I have here, none of the breakpoints are being hit. I hope its just something silly I am missing on my part ...

DemoEF6_Caching.zip
Coordinator
Sep 2 at 7:22 AM
Thanks, I will take a look at this.

Pawel
Coordinator
Sep 8 at 4:52 AM
I looked at the attached project a little bit today and the reason why caching is not working (and none of the breakpoints are being hit) is that the app is actually using EF5. I know that it might sound surprising but this is because the app is using the EF5 EntityDataSource control which creates an EF5 ObjectContext under the hood. Since the same edmx file and POCO entities can work in both EF5 and EF6 things just happened to work without crashing. You can see this for yourself if you set a breakpoint in the Order ctor and take a look at the stack (see below) - you will notice that System.Data.Entity.dll is being used (e.g. System.Data.Entity.dll!System.Data.Objects.ObjectQuery) which indicates EF5.

Thanks,
Pawel
DemoEF6_Caching.dll!DemoEF6_Caching.Order.Order() Line 17 C#
EntityFrameworkDynamicProxies-DemoEF6_Caching!System.Data.Entity.DynamicProxies.Order_9C545C0A860F9F60D2A1178F1CB0E3B61478E3DC57D7DDBDD0ECD853598C714E.Order_9C545C0A860F9F60D2A1178F1CB0E3B61478E3DC57D7DDBDD0ECD853598C714E() Unknown
[Lightweight Function]  
System.Data.Entity.dll!System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly<DemoEF6_Caching.Order>(System.Func<System.Data.Common.Internal.Materialization.Shaper,System.Data.Objects.Internal.IEntityWrapper> constructEntityDelegate, System.Data.EntityKey entityKey, System.Data.Metadata.Edm.EntitySet entitySet) Unknown
[Lightweight Function]  
System.Data.Entity.dll!System.Data.Common.Internal.Materialization.Coordinator<DemoEF6_Caching.Order>.ReadNextElement(System.Data.Common.Internal.Materialization.Shaper shaper)    Unknown
System.Data.Entity.dll!System.Data.Common.Internal.Materialization.Shaper<DemoEF6_Caching.Order>.SimpleEnumerator.MoveNext()    Unknown
System.Data.Entity.dll!System.Data.Objects.ObjectViewQueryResultData<DemoEF6_Caching.Order>.ObjectViewQueryResultData(System.Collections.IEnumerable queryResults, System.Data.Objects.ObjectContext objectContext, bool forceReadOnlyList, System.Data.Metadata.Edm.EntitySet entitySet)   Unknown
System.Data.Entity.dll!System.Data.Objects.ObjectViewFactory.CreateViewForQuery<DemoEF6_Caching.Order>(System.Data.Metadata.Edm.TypeUsage elementEdmTypeUsage, System.Collections.Generic.IEnumerable<DemoEF6_Caching.Order> queryResults, System.Data.Objects.ObjectContext objectContext, bool forceReadOnly, System.Data.Metadata.Edm.EntitySet singleEntitySet) Unknown
System.Data.Entity.dll!System.Data.Objects.ObjectResult<DemoEF6_Caching.Order>.GetIListSourceListInternal() Unknown
System.Data.Entity.dll!System.Data.Objects.ObjectResult.System.ComponentModel.IListSource.GetList() Unknown
System.Data.Entity.dll!System.Data.Objects.ObjectQuery<System.__Canon>.GetIListSourceListInternal() Unknown
System.Data.Entity.dll!System.Data.Objects.ObjectQuery.System.ComponentModel.IListSource.GetList()  Unknown
System.Web.Entity.dll!System.Web.UI.WebControls.EntityDataSourceQueryBuilder<DemoEF6_Caching.Order>.Execute(System.Data.Objects.ObjectQuery<DemoEF6_Caching.Order> queryT)  Unknown
System.Web.Entity.dll!System.Web.UI.WebControls.EntityDataSourceView.ContinueSelectTyped<DemoEF6_Caching.Order>(System.Web.UI.DataSourceSelectArguments arguments, System.Web.UI.WebControls.EntityDataSourceQueryBuilder<DemoEF6_Caching.Order> queryBuilder, System.Data.Objects.ObjectQuery<DemoEF6_Caching.Order> queryT, bool wasQueryModified)    Unknown
System.Web.Entity.dll!System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelectTyped<DemoEF6_Caching.Order>(System.Web.UI.DataSourceSelectArguments arguments, System.Web.UI.WebControls.EntityDataSourceQueryBuilder<DemoEF6_Caching.Order>.Creator qbConstructor)