Print Page | Close Window

Selectively Remove queries from QueryCache

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4080
Printed Date: 04-May-2025 at 10:10am


Topic: Selectively Remove queries from QueryCache
Posted By: myr_zero
Subject: Selectively Remove queries from QueryCache
Date Posted: 25-Mar-2013 at 7:07pm
Hi

I am trying to write code to manually manage EntityManager cache. I have code which gives me the list of entities which needs to be removed from the EntityCache.

What I want to do is remove the entity form EntityCache and remove related queries from QueryCache.

DevForce provide method RemoveEntity which takes two parameters. First parameter is entity and second parameter is flag to clear query cache. If I do not provide second parameter or provide it as true, then DevForce clears the whole QueryCache, not just the queries related to the entity being removed. This is not solution for me since I dont want to remove all the queries.

So I decided on using QueryCache.Remove method. This method comes with three signatures. Two of which use EntityKey. I dont have entity key with me now. So I have to use the other method which use Entity Type.

I use it like this

entityManager.QueryCache.Remove(entity.GetType())

But this seems to be not doing the work. I can still see the same queries present in the QueryCache. A query which uses the specified type of entity is not removed from the query cache.

Any help in this would be appreciated


Thanks



Replies:
Posted By: sbelini
Date Posted: 26-Mar-2013 at 10:49am
Hi myr_zero,

I was able to reproduce the issue. I am filing a bug and will let you know once we have a fix.


Posted By: myr_zero
Date Posted: 26-Mar-2013 at 6:18pm
Oops!! That is bad news for me.

Even I tried with EntityKey as parameter to QueryCache.Remove method. This is not working too.

Is there estimated time on when the fix for this bug be available?

Thanks you


Posted By: sbelini
Date Posted: 01-Apr-2013 at 10:40am
myr-zero,

We don't have an estimated date for this fix.

I'd suggest relying on DevForce to manage the QueryCache.

Note that since manually managing the QueryCache is not very common and DevForce manages it properly, this issue ranks lowers in our priority list.

Kind regards.


Posted By: myr_zero
Date Posted: 02-Apr-2013 at 8:51pm
Hi

We are using Optimized QueryStrategy. So when the same query is called again we want to make use of Cache. But as the number of queries getting executed increases, number of queries in QueryCache and hence number of entities in EntityCache will also increase. 

Some of the queries, entities which were called in the start of the application will remain in the cache for the life time of application even though they are not used anymore. we want to remove those entities and queries from Cache.

And also some of the entities which were not accessed since a specific time duration, need to be removed/refreshed.

The purpose of this is to optimized utilization of memory. We have large database with lots of entities. We don't want to pile up memory with a large Cache. At the same time we don't want to miss the advantage of using cache for better performance.

This is the reason to go for manual management of Cache.

If you can suggest any alternative or any such implementation already provided by DevForce which we are not aware, then it would be really helpful for us.


Thanks
Manju


Posted By: mgood
Date Posted: 02-Apr-2013 at 11:42pm
Manju,
It sounds like your rather large application is using a single EntityManager for everything. That's fine for a small application, but a large application should be broken up into units of work, each one using its own EntityManager. For commonly used entities a second level cache approach can be utilized. You may wanna take a look at our reference application where you can see this in action. There is a series of videos that walk you through the code etc.

http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-reference-application - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-reference-application


Posted By: myr_zero
Date Posted: 03-Apr-2013 at 11:49pm
Hey mgood

Thanks for your suggestions. That's a very nice documentation there.

In my case the whole idea behind using a common EntityManager for the application is "better performance".

When the same page is revisited, we don't want to load all the data again from database. If we make use of cache, then we save lot of time.

But in other way, we don't want to keep the outdated entities in cache. It is possible that some thing might have been updated in database from some other client. So at certain intervals we want to remove SPECIFIC(not all) entities from cache, so that we get latest to show when queried for. And also we don't want to occupy more memory with more data. That is the other reason we want to clear some entities at regular intervals.

Using a different entity manager for each unit of code won't give the advantage of loading from cache when it is revisited. If all separate EntityManagers are made to persist for the life time of application then again comes the problem with memory consumption.

So if QueryCache.Remove is working properly or RemoveEntity method automatically handles removing of only related queries from query cache, then it would solve problem of all developers who want to take care memory.


Thanks
Manju



Print Page | Close Window