Wednesday, March 7, 2012

Cache only a dropdown in a page, with data returned by database

Dear Friends,

I want your help to know the best way to cache the data of a dropdownbox returned by a SQL Query.(SELECT FIELD FROM DBO.TABLE)

This data returned by database is used in more than one dropdown on multiple pages. I want to cache only the dropdown control, not the entire page. Which is the best way to do it? The data isn't refreshed often, probably once per month.

Could you tell me the best way?

THANKS

You can cache the data that is used to populate the ddl.
For example, if you are getting you data as a DataTable, you could do it something like this:

Public Function GetDdlData()As DataTable'try to get the data from the CacheDim dataAs DataTable =DirectCast(HttpContext.Current.Cache.Item("GetDdlData_UniqueCacheKey"), DataTable)If dataIs Nothing Then'Cache miss data = GetSomeDatafromSqlServer()'run your code to actually hit the database here 'then cache the data object..for example with a 2 hour sliding cache expiration HttpContext.Current.Cache.Add("GetDdlData_UniqueCacheKey", data,Nothing, DateTime.MaxValue,New TimeSpan(2, 0, 0), CacheItemPriority.Normal,Nothing)End If Return dataEnd Function
|||

hi,

i suggest you to fetch data in dataset and cache it instead of dropdown as you've mentioned its used in multiple dropdwons. and below link suits best i guess whats called as

SQL Cache Invalidationhttp://www.microsoft.com/belux/msdn/nl/community/columns/desmet/dbcacheinvalidation.mspx

Hope it helps.

thanks,

satish.

|||

Currently, I'm using the object objDataSource to link to ADO.NET objects in XSD file.

But tell me your opinion about the best way/performance, to link to a database, read data, insert the values in a dropdownlist and cache these values.

using triggers in database with SQLDependency is good for performance? Give me your opinions!!

THANKS For all your support.

|||

On more note: I'm using SQL Server 2005 and Visual Studio 2005.

Thanks!

No comments:

Post a Comment