Solved

caching dropdownlist

Posted on 2006-11-13
11
201 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 7

Author Comment

by:Camillia
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Author Comment

by:Camillia
Comment Utility

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
Comment Utility
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
Comment Utility

 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 500 total points
Comment Utility
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
Comment Utility

" 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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now