2nd Level Cache, OpenAccessLinqDataSource and Views

4 posts, 1 answers
  1. Eric
    Eric avatar
    13 posts
    Member since:
    Jan 2013

    Posted 11 Apr 2013 Link to this post

    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
  2. Answer
    Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 15 Apr 2013 Link to this post

    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 >>
  3. DevCraft banner
  4. Eric
    Eric avatar
    13 posts
    Member since:
    Jan 2013

    Posted 18 Apr 2013 Link to this post

    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
  5. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 19 Apr 2013 Link to this post

    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 >>
Back to Top