locked
Caching non-volatile query results with an attached database data source RRS feed

  • Question

  • To help wil scalability, this article shows us a nice way to cache query results when using a RIA domain service: Use Caching to Turbo-Boost your LightSwitch Apps but I want to achieve the same on certain queries with a native attached database data source in LS.

    My first experiment was (assuming my data service is called MainData and the entities to be cached are called ClientStatuses):

    1. create a new partical class MainData
    2. implementing the OnContextCreated() method (this method is abstract in the generated MainDataObjectContext.cs)
    3. in the above method I call:  base.CreateObjectSet<ClientStatus>("ClientStatuses"); and add it to cache if not already added to cache and then set it to the private _ClientStatuses variable in the same way as the public ObjectSet<ClientStatus> ClientStatuses {} property get method would do

    The above all compiles and runs and the cache is set as expected, but the query for ClientStatuses still hit the database each time the client is refreshed. So obviously more needs to be cached...

    I understand that we should really take query parameters into account and have also looked at utilising the global Query_Executing() and Query_Executed() methods but haven't had any luck with that as yet.

    I found the following article regarding second level cache with the EF: Second Level Cache for Entity Framework 6.1 but not sure we can easily hook that into the LS object context.

    Has anyone done any caching like this for attached database data sources?


    Regards, Xander. My Blog


    • Edited by novascape Monday, November 10, 2014 11:41 PM
    Monday, November 10, 2014 10:37 PM

All replies

  • data.js supports the concept of "caches" as well, so caching entities on the client could be another option: Using Caches

    Regards, Xander. My Blog

    Monday, November 10, 2014 10:41 PM
  • what is native attached database data source ??
    Wednesday, November 12, 2014 6:31 AM
  • what is native attached database data source ??
    My terminology for a LS data source attached to an "external" database as opposed to an "intrinsic" database.

    Regards, Xander. My Blog

    Wednesday, November 12, 2014 8:01 AM