?
Solved

caching dropdownlist

Posted on 2006-11-13
11
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 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