Application State and Custom Collection Maintenance

  • Thread starter Thread starter Jeff S
  • Start date Start date
J

Jeff S

I'm storing a list of widgets in a database. The list changes infrequently
(twice per week at most), and is relatively short (200 items at most, with
very little detail per item). A small subset of all possible widgets will be
displayed on a page (using VB.NET/code behind). I plan to populate a custom
collection/class with a list of all possible widgets. The class will include
a method that returns the required subset. Of course the logic will have to
hit the database in order to populate a custom collection. Because I want to
minimize the number of hits on the database, and because the class will hold
relatively little data, and because and the data is identical for all users,
I think it makes sense to maintain it in the Application state.

My questions:
1. When/where should I instantiate and initialize the custom
collection/class? It seems that if I do it in the page_load event of
Default.aspx, that I'd hit the database too much (every time a user opens
the application). But, if not during that event, then when should it be
initialized?

2. When the list of widgets gets updated in the database (twice per week or
so), the custom collection/class would need to be refreshed in order to
include the changes made in the database. What would be a good stragegy for
keeping the custom collection/class synchronized with the database?

Thanks in advance.

Jeff
 
Hi,

1) You can initialize the cache in application_onstart event.
(Initialization will happen just once).

2) You can use two attitudes:
- wrap accessing cache data with method that will check if cache
expired and if expired re-add the data from DB to cache.
- catch the callback event that send by cache after the cache releases
the data and add again the data from the DB.

HTH

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
Back
Top