Home All Groups Group Topic Archive Search About

how to cache a datatable every X time

Author
10 Jan 2007 1:14 PM
urielka
i have a web app where i have a Singleton holding a bunch of
datasets(Instances not classes).
one dataset have some dynamic data that i want to update once a
while,that dataset is accessed by other part of the app
..
i saw that the DataTable is multi-reader,one-writer,i tried using a
timer but some times it made the all site to stuck for a few seconds
and it crashed my testing server.

then i tried to make a aspx web page that cache the DataTable and a
windows service that call it every 5 minutes,but using that way i get a
weird thing controls that bind to that datatable such as repeater
doesn`t show the data from the datatable all time,sometime it shows and
sometimes it doesn`t show it( i only update three columns of that
datatable and that three columns are the ones that doesn`t always show
in the controls the other columns work just fine) this problem i have
with both ways.

when i cache part of that datatable(those 3 columns) i execute a Stored
procedure and use a SqlDataReader to read the data and update the
datatable according to the new data(i don`t update all the table just
three columns in every row).

my big question is:
what is the best way to cache the DataTable(part of it) from the
Database every X time?

i can`t use just a windows service as the DataTable live only in the
application process.

Author
10 Jan 2007 4:00 PM
dsandor
urielka,

Why do you not use the System.Web.Caching.Cache class to cache up your
DataTables?  It is very helpful because you can set either a hard timeout or
a sliding timeout on the object you have cached.  Additionally, when you
cache up the object you pass it a reference to a method you created that the
cache manager calls when it decides the object is expired.

In this method you create (the callback) you can do all you need in order to
re-cache the object.

You have access to the cache classes in your aspx code Page.Context.Cache
(from memory).

-David Sandor


http://msdn2.microsoft.com/en-us/library/system.web.caching.cache.aspx

Show quote
"urielka" wrote:

> i have a web app where i have a Singleton holding a bunch of
> datasets(Instances not classes).
> one dataset have some dynamic data that i want to update once a
> while,that dataset is accessed by other part of the app
> ..
> i saw that the DataTable is multi-reader,one-writer,i tried using a
> timer but some times it made the all site to stuck for a few seconds
> and it crashed my testing server.
>
> then i tried to make a aspx web page that cache the DataTable and a
> windows service that call it every 5 minutes,but using that way i get a
> weird thing controls that bind to that datatable such as repeater
> doesn`t show the data from the datatable all time,sometime it shows and
> sometimes it doesn`t show it( i only update three columns of that
> datatable and that three columns are the ones that doesn`t always show
> in the controls the other columns work just fine) this problem i have
> with both ways.
>
> when i cache part of that datatable(those 3 columns) i execute a Stored
> procedure and use a SqlDataReader to read the data and update the
> datatable according to the new data(i don`t update all the table just
> three columns in every row).
>
> my big question is:
> what is the best way to cache the DataTable(part of it) from the
> Database every X time?
>
> i can`t use just a windows service as the DataTable live only in the
> application process.
>
>

AddThis Social Bookmark Button