Winforms - Caching Data

JRockFL
JRockFL used Ask the Experts™
on
I have a winforms application and would like to cache the look up tables when the application loads.
I would like to have a collection of table names and then when the application loads, iterate through the collection
and then cache each table.

Any suggestions to get me started?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Subscribe
Most Valuable Expert 2012
Top Expert 2014

Commented:
You can declare some DataTable objects at the module level. In the form load of the main form, load these tables. Then you can use these tables across the whole application. Any variable/function in module has an application level scope.
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Author

Commented:
CodeCruiser,

Thank you for your reply. I actual use entities objects for data and another class that inherits from collectionbase class.

Public Class StatesCollection
   Inherits CollectionBase
End Class


Without making this a shared class, what do you suggestion for caching?
I wanted to have a table that just stored the table name, then I could iterate through all of the tables.


Public Class TableCache

End Class

Public TableCacheCollection
   Inherits CollectionBase
End Class

For each tc As TableCache in TableCacheColletion
'cache the some objects
'what do you suggest?
Next
Most Valuable Expert 2012
Top Expert 2014

Commented:
I am not sure why you want to store the table names in the collection and have the caching enabled by this. You need to store the table contents somewhere as well. If you dont know the table names and how do you use them in code?

Author

Commented:
I wanted to store the names of the tables that I want to cache.
So I would have table in Sql Server called TableCache.
In this table, I would then list all of the names of the tables that I would want to cache.
For example, States.

Then When the application loaded, I could query the tablecache table and determine all of the tables that would be cached.

Does that make sense?
Most Valuable Expert 2012
Top Expert 2014

Commented:
Yes. But that is not much complicated is it? Do you need to code for writing to and reading from this table?

Author

Commented:
Ok let's not worry about that then.
What do you recommend for caching objects like this then?


Public Class StatesCollection
   Inherits CollectionBase
End Class

Most Valuable Expert 2012
Top Expert 2014

Commented:
I would use variables in a module to store these objects.

Author

Commented:
Ok, can you provide me a quick code sample?
I'm not familiar with a module
Most Valuable Expert 2012
Top Expert 2014
Commented:
Right click on the project, select Add New Item. From the dialog, choose module. A new file called Module1.vb would be added to your project. Open it and just declare the variables like

Public MyVar as String

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial