Solved

caching dropdownlist

Posted on 2006-11-13
11
204 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
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.

 
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 500 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 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