Search code examples
c#cachingsql-server-expressdata-access-layer

Caching DAL return objects?


I was wondering if i should be caching the objects returned from my DAL in some way? I may have multiple UI controls calling for the same data in a single load of the page.

What would you guys recommend? Am i begin a little to cautious? Its not a terrible amount of data. But if i should be caching in some way, what would be the recommended approach?


Solution

  • You could cache AND if you really have multiple controls on the same page using the same data you can call the data once in the parent page and pass a reference to it to each control with a Setter in each control (rather than have each control pull the same data from the DAL themselves), eg:

    myControl.AllUsers = _allUsers;
    ....
    myOtherControl.AllUsers = _allUsers;
    

    I also agree with @DanielHilgarth. Caching adds complexity (when to refresh the cache, for example). If the page loads quickly anyway, I wouldn't bother.

    If the page is slow, database calls in loops are often the culprit in my experience.