This is a migrated thread and some comments may be shown as answers.

2nd Level Cache, OpenAccessLinqDataSource and Views

3 Answers 48 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eric
Top achievements
Rank 1
Eric asked on 11 Apr 2013, 05:52 PM
Hello everyone,

My question is in regarids to how the 2nd level cache might behave with an OpenAccessLinqDataSource using a view. So, for example I have two tables in the database:

Cars and Category

I also have a view that combines the two as viewCarsAndCategories.

So, let's say I make a change to Cars and save that like this: databaseContext.SaveChanges();

The 2nd level cache will evict the Cars entities that changed as I understand it. Next time Cars is called new data will be pulled from the database.

But....... the entities belonging to viewCarsAndCategories won't change, and if I am using an OpenAccessLinqDataSource that uses this view, it will pull old data because the 2nd leve cache doesn't know the view cached data should be evicted.

Is that right?

So.... for the OpenAccessLinqDataSource to get the new data, I shouldn't use a view. Instead, I should use a custom "GroupBy" parameters like shown here. for example: the select box will have the following:

new(CarID, Make, Model, Category.ID, Category.CategoryName)

Now, the OpenAccessLinqDataSource should be drawing uplon entities that are changed in the 2nd level cache.  When I save changes to Cars, the data pulled by my OpenAccessLinqDataSource should also change.

Do I have this correct? WIll this work?

Thanks!!!

-Eric

3 Answers, 1 is accepted

Sort by
0
Accepted
Kaloyan Nikolov
Telerik team
answered on 15 Apr 2013, 02:25 PM
Hello Eric,

Yes, your understanding is correct. Please find more details for the approach with the views in your support ticket.  

About the approach using projection with an anonymous type it looks good. The Second Level Cache should work in this case. Telerik OpenAccess ORM caches the query results, in this case the query result depends on the parameters (passed in the where clause) and on the persistent classes used to form the anonymous type. If you modify, add or delete an entity of these classes (Car or/and Category) the query returning the anonymous type will be influenced as well. 

I hope this helps. Do not hesitate to contact us again if you have any other questions. 

Kind regards,
Kaloyan Nikolov
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
0
Eric
Top achievements
Rank 1
answered on 19 Apr 2013, 01:10 AM
Hello Kaloyan!

Thank you for the great advice you sent me via support ticket. I basically got rid of using almost all views, except for the ones that do certain calculations so now the 2nd level cache does almost all the tracking of entities.

I also created a custom database context following your example so I can trigger Evicts of cached database view entities. Now, all my data sources and code use that context.

I refined it a bit further, however. In the example you sent me it used "EvictAll" which, as the name implies, evicts all cached entities of the type given. I augmented that a bit to only evict entites of the view that I know actually changed. I get the key's of the entities that I know changed, and I check if they are in cache. If they are, I "boot them) (i.e. Evict).

It runs like a charm now! Huge boost in performance on our website. Thanks!

-Eric
0
Kaloyan Nikolov
Telerik team
answered on 19 Apr 2013, 08:58 AM
Hello Eric,

I am glad to help you make better use of Telerik OpenAccess ORM. 

We stay on your disposal if you have any further questions.
 

Greetings,
Kaloyan Nikolov
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
Tags
Development (API, general questions)
Asked by
Eric
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Eric
Top achievements
Rank 1
Share this question
or