Second Level Cache Beta-2 for EntityFramework 6.1+ shipped

When I published the Beta version of EFCache back in May I intentionally did not call it Beta-1 since at that time I did not plan to ship Beta-2. Instead, I wanted to go straight to the RTM. Alas! It turned out that EFCache could not be used with models where CUD (Create/Update/Delete) operations where mapped to stored procedures. Another problem was that in scenarios where there were multiple databases with the same schema EFCache returned cached results even if the database the app was connecting changed. I also got a pull request which I wanted to include. As a result I decided to ship Beta-2. Here is the full list of what’s included in this release:

  • support for models containing CUD operations mapped to stored procedures – invoking a CUD operation will invalidate cache items for the given entity set
  • CacheTransactionHandler.AddAffectedEntitySets is now protected – makes subclassing CacheTransactionHandler easier
  • database name is now part of the cache key – enables using the same cache across multiple databases with the same schema/structure
  • new Cached() extension method forces caching results for selected queries – results for queries marked with Cached() method will be cached regardless of caching policy, whether the query has been blacklisted or if it contains non-deterministic SQL functions. This feature started with a contribution from ragoster
  • new name – Second Level Cache for Entity Framework 6.1+ – (notice ‘+’) to indicate that EFCache works not only with Entity Framework 6.1 but also with newer point releases (i.e. all releases up to, but not including, the next major release)

The new version has been uploaded to NuGet, so update the package in your project and let me know of any issues. If I don’t hear back from you I will release the final version in a month or so.

11 thoughts on “Second Level Cache Beta-2 for EntityFramework 6.1+ shipped

  1. Hi Pawel,
    first I want to thank you for the hard work!

    I use your EfCache in my running webapplication and since there I get the following error sometimes:

    “Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries”

    StackTrace:
    bei System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
    bei System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
    bei System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
    bei System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
    bei System.Data.SqlClient.SqlDataReader.get_MetaData()
    bei System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
    bei System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
    bei System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
    bei System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
    bei System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
    bei System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
    bei EFCache.CachingCommand.ExecuteDbDataReader(CommandBehavior behavior)
    bei System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
    bei System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
    bei System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

    Thanks and and best regards!

    Like

    1. Sorry, the error has nothing to do with your EfCache.
      The problem came from this linq query:
      “query.Where(x => words.All(w => x.Title.Contains(w)))” // words.Length to big!

      Like

      1. I am glad you were able to resolve the issue. I was about to comment that it is unlikely the issue was introduced by the cache since the cache does not rewrite/change the SQL queries.

        Thanks,
        Pawel

        Like

  2. Hi Pawel, I tried to implement a custom CachingPolicy to exclude specific tables (contains spatial column).
    The problem is, that you declare the virtual method as internal:
    protected internal virtual bool CanBeCached
    Are threre any reasons you did that?
    Thanks

    Like

      1. Thanks for your quick response! I didn’t know the ‘protected internal’ access modifiers.

        (The error happens through different Entity-Framework versions in my assemblys)

        Thanks

        Like

Leave a reply to Mike Cancel reply