[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Bobstar

8/8/2006 11:32:00 PM

But I'm a bit confused. I've read all about the Caching in patterns and
practices, but somehow I dont quite get it.

I need a way to Cache a DataTable, the DataTable is located in my
businesslayer - and I want to share that DataTable between multiple request
to the application. The DataTable only expires once every midnight and takes
a long time to populate with data, so I need to cache it somehow.

I've tried using HttpContext.Current - but that is'nt applicationwide as I
need it to be. Should I make something i the Application_onstart, and if so -
how do I provide an Expirationpolicy out there? Can I access the
ApplicationCache from my businesslayer and thereby renew the Cache og Remove
it??

Hope you understand what I'm trying to accomplish :-)

Kind regards

2 Answers

liuchenzhong

9/7/2006 8:32:00 PM

0

you need to use httpruntime.cache for application level caching.

check here for reference:
http://msdn2.microsoft.com/en-us/library/system.web.httpruntime_me...

:)

<DIV>&quot;Bobstar&quot; &lt;Bobstar@discussions.microsoft.com&gt; wrote in
message news:E63618E4-2621-4A63-98D4-3F10EDE77268@microsoft.com...</DIV>>
But I'm a bit confused. I've read all about the Caching in patterns and
> practices, but somehow I dont quite get it.
>
> I need a way to Cache a DataTable, the DataTable is located in my
> businesslayer - and I want to share that DataTable between multiple
> request
> to the application. The DataTable only expires once every midnight and
> takes
> a long time to populate with data, so I need to cache it somehow.
>
> I've tried using HttpContext.Current - but that is'nt applicationwide as I
> need it to be. Should I make something i the Application_onstart, and if
> so -
> how do I provide an Expirationpolicy out there? Can I access the
> ApplicationCache from my businesslayer and thereby renew the Cache og
> Remove
> it??
>
> Hope you understand what I'm trying to accomplish :-)
>
> Kind regards
>

msnews

9/11/2006 11:54:00 AM

0

There are a few options. It normally is a good idea to use the Cache
whenever possible to hold onto data. In this case you want to ensure that
the cache does not remove it for a long time.

What you can do is set up a cache policy which you use when you add the item
to the cache. You will use this value for the CacheItemPriority.

System.Web.Caching.CacheItemPriority.NotRemovable

You can attache the CacheItemRemovedCallback.

Here is a VB.NET snippet.

Dim onRemove As CacheItemRemovedCallback = New
CacheItemRemovedCallback(AddressOf RemovedCallback)

Cache.Add(key, obj, Nothing, DateTime.Now.AddSeconds(seconds), _
TimeSpan.Zero, CacheItemPriority.NotRemovable, onRemove)

What you could do is have the item expire once every 60 minutes and add it
back into the cache if it is between midnight and 1am. At that point you
get a fresh copy and add it to the cache.

However, if this DataTable does take a long time to load, you may still
experience problems. At any time during the day the Application Pool could
reset itself and cause the web application to restart and reload this
DataTable. It may be best to tune the loading of this data. I will assume
this data is being loaded from a query joining across many tables with
multiple subselects and inner and outer joins. With ASP.NET 2.0 you should
be able to quickly load a lot of data as long as the query is simple. So
what you can do is schedule a DTS package to run that complex query to
populate a simple table with the results, called WarehouseTable1. Then you
just run this query to populate your DataTable.

select * from WarehouseTable1

That should load very quickly. You may be surprised how fast it can be.

If this is not an option because the query is still slow due to a slow
network connection, another method would be to run a scheduled job to run a
..NET utility to load this query into a DataTable and serialize it out the an
XML file. Then place that XML file onto the web server and have it use that
file as the datasource. You can then update the XML file and use the Cache
dependency to reload the XML file whenever the file changes.

http://www.eggheadcafe.com/articles/20...

You have a lot of great ways to tune this performance.

Brennan Stehling
http://brennan.offwhite...


"Bobstar" <Bobstar@discussions.microsoft.com> wrote in message
news:E63618E4-2621-4A63-98D4-3F10EDE77268@microsoft.com...
> But I'm a bit confused. I've read all about the Caching in patterns and
> practices, but somehow I dont quite get it.
>
> I need a way to Cache a DataTable, the DataTable is located in my
> businesslayer - and I want to share that DataTable between multiple
> request
> to the application. The DataTable only expires once every midnight and
> takes
> a long time to populate with data, so I need to cache it somehow.
>
> I've tried using HttpContext.Current - but that is'nt applicationwide as I
> need it to be. Should I make something i the Application_onstart, and if
> so -
> how do I provide an Expirationpolicy out there? Can I access the
> ApplicationCache from my businesslayer and thereby renew the Cache og
> Remove
> it??
>
> Hope you understand what I'm trying to accomplish :-)
>
> Kind regards
>