|
| Session-specific caching |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.framework.aspnet.caching.
| Jeffrey H |
I have a specific caching requirement for the menus on my site, and I am looking for tips on how to get it working. My ASP.NET site supports a set of menus that must be rendered individually for every user on the site, and for the duration of their session only. Every user gets the same menus, but the menus contain dynamic parameters that differ between users. Once the user has logged in, the menus are constructed for them. The menus will not change anymore, so they only need to render once. Future views of the menus can come from a cache.
My challenge is this: I want the menus to cache for individual users for the duration of their sessions only. Once they log out, I want their menus to be removed from the cache as well, so that they can be reconstructed the next time the user logs in. So, User A has their own cached version of the menus, while User B has another version, and so on.
What is the best way to implement this requirement?
Thanks in advance -
Jeff
|
|
|
| |
|
| |
| |
| Nicolas Dario Ortiz Sanna |
Hi Jeffrey, first of all, forget my english .I'm from argentina.
I'm in the same situation as you. My answer for that was creating an ArrayList and store this on a session variable. Then I have a usercontrol that creates the menu.
In every item of the array I store an object with this properties: Menu : The name of the menu ID: The ID of the menu SubMenu: An ArrayList (so menues can have submenues) URL: The URL (so this item can point to a page)
The Submenu ArrayList has Items with the same structure of the Menu ArrayList
In the user control I used 1 Repeater to create the Main menu and inside each Item of the Repeater I have another Repeater (to create the submenu)
I retreive the menuitems at the beggining of the session, create the arrayList and store it in a session variable, then inside each page i used the usercontrol that is cached using VaryByCustom and the name of the user (so the menu is store in the cache for each user)
That way i go one time to the database and 1 time to create the menu (and every xx seconds, which is the time of the cache duration, i recreate the menu using the session variable)
If you need help, i can show you the code i use.
Nicolas
"Jeffrey H" <Click here to reveal e-mail address> wrote in message news:OM4uZVQ0BHA.2792@tkmsftngp05... [Original message clipped]
|
|
|
| |
|
| |
| |
| Ian Reyes |
If i understood correctly, you were able to cache a version of a page depending on a session variable? In short, implemented a "VarybySession"?
Would you mind showing me how?
Thanks alot! Ian
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
|
|
|
| |
|
|
| |
| |
| Paul Wilson |
You cannot cache pages based on Session variables, but you can use Cookies with VaryByCustom attribute.
Place the following in Global.asax.cs:
public override string GetVaryByCustomString(System.Web.HttpContext context, string custom) { if (custom == "StyleSheet"){ return "StyleSheet=" + this.Request.Cookies["StyleSheet"]; } }
I also wrap the Request.Cookies["StyleSheet"] with a utitility function I have to handle it when it is null.
Then place the following directive at top of page:
<%@ OutputCache Duration="600" VaryByCustom="StyleSheet" %>
|
|
|
| |
|
| |
|
|
|
| |
| Gedas Gudenas |
Use dependency caching and assign user id, or session id as a key. Just store xml, html or whatever you use based on that key in the cache object and then retrieve it. Make sure to remove and add a new menu when user signs in. Here is an article on how to do this: http://www.dotnet101.com/articles/art009_aspcaching.asp
"Jeffrey H" <Click here to reveal e-mail address> wrote in message news:OM4uZVQ0BHA.2792@tkmsftngp05... [Original message clipped]
|
|
|
| |
|
| |
| |
| Jeffrey H |
Thanks everyone for the feedback. Everyone's suggestions were helpful, but I'm still looking for the best approach. My requirement is, I need to cache a menu UserControl, which possesses HTML, code-behind and JavaScript. It's very tricky to cache something like this, because there are so many "dimensions" to it. It's not like a simple object that I can load up on a whim. The best approach for me is probably a combination of boh: I will cache just the menu data, not the entire UserControl. Further, I think I prefer to use the Cache() API with dependency, instead of Sessions.
This would all be so much simpler if we could cache embedded Usercontrols by parameter WITHOUT requiring that they be able to process their own posts, in order to cache.
Thanks again -
Jeff
"Gedas Gudenas" <Click here to reveal e-mail address> wrote in message news:#F5GfEd2BHA.2388@tkmsftngp04... [Original message clipped]
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|