sarat
sarat

Reputation: 11130

Client Side Caching C# Forms Application

I have an application which query the database for records. The records can be thousands in numbers and this can shoot up the memory of the process and eventually leads up to a crash or slow in response.

The paginated query is a solution for this but the information in the record always keep changing. Hence to give a unique experience, we are forced to show the information available at the time which user make the query.

Employing paging could dynamically update the content on moving from pages to page. I believe a client-side caching could solve this problem.

One way I am finding is to store the results in to disk in XML format and query using LINQ to XML. Are there any proven client side caching mechanism which can work with desktop application (not web)

Upvotes: 0

Views: 2616

Answers (2)

iSamnium
iSamnium

Reputation: 386

See some pattern like http://msdn.microsoft.com/en-us/library/ff664753 It talks about the use of the Enterprise Library Caching Application Block that lets developers incorporate a local cache in their applications.

Read also http://www.codeproject.com/Articles/8977/Using-Cache-in-Your-WinForms-Applications

Enterprise Library 5.0 can be found here http://msdn.microsoft.com/en-us/library/ff632023

Upvotes: 2

idlemind
idlemind

Reputation: 686

Memory usage shouldn't really be an issue unless you are letting your cache grow indefinitely. There is little benefit to pre-fetching too many pages the user may never see, or in holding on to pages that the user has not viewed for a long time. Dynamically fetching the next/previous page would keep performance high, but you should clear from the cache pages that have been edited or are older than a certain timespan. Clearing from the cache simply requires discarding all references to the page (e.g. removing it from any lists or dictionaries) and allowing the garbage collector to do its work.

You can also potentially store a WeakReference to your objects and let the garbage collector collect your objects if it needs to, but this gives you less control over what is an isn't cached.

Alternatively there are some very good third party solutions for this, especially if its a grid control. The DevExpress grid controls have an excellent server mode that can handle very large data sets with good performance.

Upvotes: 1

Related Questions