Maybe this cache should support DbGeometry

Nov 18, 2014 at 4:20 PM
public class MyObject
{
    public int Id {get;set;}
    public DbGeometry Shape {get;set;}
}
This class can't put into the cache.
Coordinator
Nov 19, 2014 at 3:48 AM
Jan 7, 2015 at 7:16 PM
Hi there,

Firstly just started looking at this Framework to help speed up my Azure hosted web site.

I have run into the DbGeography issues as above.

I have been trying something to get round this by using the CanBeCached override on my own cache policy.

I am only using a spatial type in one Entity in the whole application so though that I could simply stop the object being cached and hence read from cache to get round this problem.

protected override bool CanBeCached(System.Collections.ObjectModel.ReadOnlyCollection<System.Data.Entity.Core.Metadata.Edm.EntitySetBase> affectedEntitySets, string sql, IEnumerable<KeyValuePair<string, object>> parameters)
    {
        if (affectedEntitySets.Any(x => x.Table == "CompanyLocations"))
        {
            return false;
        }

        return true;

    }
It kind off works expect I am getting some very strange results. Basically nothing is ever returned now for any Query that contains the table. So my app is now throwing lots of null exceptions etc.

I thought it would simply bypass your cache and return from EF as normal. Is that not what should happen by using this override?

Thanks

Rob
Jan 8, 2015 at 8:16 AM
Please ignore my last post.

Error in my app, not in the framework

For others I have isolated my Geography data into a small object and simply ignore that from the cache by using the NoCache() method.
Coordinator
Jan 8, 2015 at 7:43 PM
@RobertMaple - Thanks for the update. I did not have time to look into yesterday and now I know I will not have to. Btw. excluding the entity sets where entity types have spatial properties is a nice workaround!
Jan 9, 2015 at 8:23 AM
Thanks.

I know this is not the correct forum but I need to ask you a question or two.
  1. I am using your framework in a web app. I read about the cache policy that you ship and you state that the object will lie around in cache until they are updated in some way. As this is in a web app and the app pool will recycle periodically I take it that will purge the cache as the InMemory mechanism will be using the memory of the application pool (IIs web site)?
  2. How is the cache handled for dynamic lazy loaded objects? I am using your framework in my repository layer which I think gives me enough control as I set a property on each repo (one for each object type) that says to cache or use the NoCache() method. Any lazy loaded objects do not go through a repo but are handled dynamically by EF. I therefore am unsure how these are cached or not?
  3. My application is deployed to Azure. I take it the simple InMemory mechanism will still work without the need to add more services or worker roles to Azure. Trying like hell to keep all hosting costs and complications to a minimum where possible
Thanks for your help

Rob

PS initial performance enhancements are looking great. Love it.
Coordinator
Jan 10, 2015 at 4:55 AM
1) Yes, killing AppDomain should purge the cache. The MemoryCache has the Purge method you could use to remove expired cache entries. If you want to keep entries across AppDomain restarts you need to use a different caching mechanism (e.g. there is an implementation that uses Redis to store cache entries).

2) Lazy loading still should work. Without cache (and if streaming is set to true which is the default behavior) EF keeps an open connection to the database (that's why the connection string must have MutipleActiveResultsets=true or lazy loading will not work in some scenarios) and reads a row when it needs it. What EFCache does is it force reads the entire resultset, store the data as an array and expose it using the DbDataReader interface. Now, the cache caches results for specific queries. If a query involves an entity set that should not be cached (because of either NotCached() or returning false from the CanBeCached() method) the results for this query will not be cached.

3) I don't see any issues with using InMemoryCache with Azure. However if you have multiple worker roles using EF each will have its own cache and entries.

Hope this helps,
Pawel
Jan 26, 2015 at 8:07 AM
Thanks very much for getting back to me.

Help greatly appreciated.