V4 - CacheResultSet not working as expected

Posts   
 
    
PatrickD
User
Posts: 65
Joined: 05-Sep-2006
# Posted on: 11-Apr-2013 14:32:02   

When I call the following code (SelfService), it performs two roundtrips to the database. I would expect that the second call would get its data from the cache.


CacheController.RegisterCache("", new ResultsetCache());

var metaData = new LinqMetaData();
var query = (from exampleEntity in metaData.Example
            where exampleEntity.Id == 1
            select exampleEntity.Status).CacheResultset(2);

var result1 = query.FirstOrDefault();  // Performs 1st call to database
var result2 = query.FirstOrDefault();  // Performs 2nd call to database, but shouldn't

(Id is the primary key, Status is an int column.)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 11-Apr-2013 15:03:36   

This is caused by the fact the cache directive is not at the outside of the query. In your situation this is of course unavoidable, as the result of FirstOrDefault isn't an IQueryable.

Looking into it. The query is read from the cache if you do ToList instead of FirstOrDefault.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 11-Apr-2013 16:56:13   

Other query types are also not working. E.g. query.Any(), query.Count(), they all don't obey the caching. We're going to log the caching directives inside they query now and merge it with the outer query, as that's the only way to make e.g. query.Any() use the caching directive as it will end up in the projection as a scalar query inside a CASE.

We've fixed it, for all these query types. Fix is attached (is also in the new build, which we'll upload within an hour or so).

Attachments
Filename File size Added on Approval
SD.LLBLGen.Pro.ORMSupportClasses.zip 409,360 11-Apr-2013 16:56.21 Approved
Frans Bouma | Lead developer LLBLGen Pro