?
Solved

caching dropdownlist

Posted on 2006-11-13
11
Medium Priority
?
215 Views
Last Modified: 2010-04-23
On my "options.aspx" page, I have a dropdownlist . I populate it by getting the values from the database...

user1 can have A1,A2,A3
User2 can have A1,A2
User3 can have A1,A2,A3

I bind the dropdownlist to an Arraylist...

How can I cache this? Should I cache it based on username? if so, then what if i have 30 users..will I have 30 cached pages in memory??

Any ideas?
0
Comment
Question by:Camillia
  • 5
  • 4
  • 2
11 Comments
 
LVL 6

Expert Comment

by:riyazthad
ID: 17929743
FarzaDW,

You can store arraylist to a session variable. In this case arraylist contains value A,B,C etc for each user.

ex:

        Dim ar As New ArrayList
        ar.Add("A")
        ar.Add("B")
        ar.Add("C")
        Session("Options") = ar

You will get this value thru out pages. Since session is user based, 30 user can hold their own values.

Thad
0
 
LVL 7

Author Comment

by:Camillia
ID: 17929771
But then next time when the user logs in, I have to ***hit the database***, get the values, store them in session again...

The dropdownlist doesnt change as often so I want to cache it....
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17930173
Then you can cache your dataset using Data Caching using insert method and even you can set expiring date or even to XML file as cache dependency.

Then each time you can test whether cache object exist or not, and take decision on hitting database.

Thad
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:Camillia
ID: 17930237
let me ask you this:

If I do that...then will be cached for EVERYONE? will everyone see the SAME cached values in the dropdownlist?...

For example, User1 should see values: A1, A2,A3
                    User2 should see values: A1, A2
                    User3 should see values: A1, A2, A3

If user1 logs in and the dropdownlist is cached, then user2 logs in..user2 would see "A1,A2,A3"..instead of "A1,A2"...correct?

0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17930432
You can store all records in dataset. So your dataset contains A1,A2,A3,A4 etc for all users. Now it is cached. When ever you logged to page, you know who logged. You may have a ID for user, then filter your dataset with your user details, suppose user1 logged in, you took dataset from cache, and filter your dataset to 3 records by filtering based on user1. And set that dataset to dropdownlist and bind. Now user2 logged in and filter based on his/her credential, and bind to dropdownlist.

Thad
0
 
LVL 7

Author Comment

by:Camillia
ID: 17930480

ah, it makes sense...I read here and another place not to use a dataset:
http://aspnet.4guysfromrolla.com/articles/050405-1.aspx

Anyway to do what you're saying using ArrayLists? then cache the arrayList?
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17930641
Yes you can cache arraylist. Depends on what your A1,A2 and its length and actual value.

Thad
0
 
LVL 7

Author Comment

by:Camillia
ID: 17930850

 i'm probably beating this to death..but with a cached ArrayList, how would I display the correct dropdownlist for the correct user??...

So, if I use the 'dataset', I can store the userID in it and as you explained, display the proper value to the user...

do the same thing with ArrayList...store the userID and the values for each user in the ArrayList?
0
 
LVL 4

Accepted Solution

by:
Xeavn earned 2000 total points
ID: 17931407
Well I don't know too much about trying to store an Arraylist in Cache, although I suppose it could be done. This is how I handled the situation.

<asp:DropDownList id="UnitsDDL"
     CssClass="tableinput"
     DataSource='<%# LoadCachedDataByKey("sp_UnitsList", "Units") %>'
     DataTextField="UNITS_ABBREV"
     DataValueField="UNITS_ID"
     SelectedValue='<%# DataBinder.Eval(Container.DataItem, "Unit.ID") %>'
     OnKeyDown="t4e();"
     Visible="False"
     RunAt="Server" />

Public Function LoadCachedDataByKey(ByVal strSP As String, ByVal strCK As String) As DataView
      Dim myContext As HttpContext
      myContext = HttpContext.Current

      Dim Source As DataView
      Dim strCacheKey As String
      strCacheKey = strCK & Convert.ToString(HttpContext.Current.Session("UserID"))

      If myContext.Cache(strCacheKey) Is Nothing Then
            Dim spQuery As New SQLCommand
            spQuery.CommandType = CommandType.StoredProcedure
            spQuery.CommandText = strSP
            Source = dw.Data.LoadData(spQuery)
            myContext.Cache(strCacheKey) = Source
      Else
            Source = DirectCast(myContext.Cache(strCacheKey), DataView)
      End If

      Return Source
End Function 'LoadCachedDataByKey

In this case the Source = dw.Data.LoadData(spQuery) is a function call to get my data from that database, and load it into a DataView, and once I have that dataview I just cache the dataview using a combination of a string and the Users ID #
0
 
LVL 7

Author Comment

by:Camillia
ID: 17931474

" I just cache the dataview using a combination of a string and the Users ID #"...where are you doing this?...

I think i need to do something similar... cache the ArrayList with the UserID...that would tell me what ArrayList goes with what user....
0
 
LVL 4

Expert Comment

by:Xeavn
ID: 17931615
strCacheKey = strCK & Convert.ToString(HttpContext.Current.Session("UserID"))

This is the line where that is done. The strCacheKey is set to be strCK which in this case is just "Units" and then the persons id number which I have stored as a Session Variable. So the CacheKey becomes Units21 for the user with id # 21 and Units34 for the user with id # 34.

Then later on if that cache doesn't exist yet, I tell it to cache the dataview under that CacheKey. (This is the line that does that.)

myContext.Cache(strCacheKey) = Source
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question