Retrive User Control from Cache

P

poolieweb

I have created a custom user control which creates a ASPxMenu ( Same
fucntion as standard menu control) from data retreved from a webservice
(Reporting Services) which deals with user access. This process is
slow. And as the menu object will not change in a session I am trying
to cache the menu with the session user as the key. The problem is that
I can not retreve the menu object after the first request. The menu
items are resident in the cahce but can not display the menu. Can any
one help? problibly be a simple ansewer , syntax maybe.

sudo code:


if cache is emtpy then
populate menu
else
menu = cache



Full Code: custom control ascx file

Imports DevExpress.Web.ASPxMenu
Imports System.Web.UI

Partial Class WebUserControl
Inherits System.Web.UI.UserControl



Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load



If
Cache(System.Net.CredentialCache.DefaultNetworkCredentials.ToString) Is
Nothing Then

'Dim ASPxMenu1 As ASPxMenu = MENU


Dim service As aureports.ReportingService = New
aureports.ReportingService

service.Url =
"http://localhost/reportserver/reportservice.asmx"
'Me.service.Credentials =
System.Net.CredentialCache.DefaultNetworkCredentials
service.Credentials = New
System.Net.NetworkCredential("test", "test")

ASPxMenu1.Items.Clear()
ASPxMenu1.Items.Add("Reports")
ASPxMenu1.Items.Add("Services")
ASPxMenu1.Items.Add("Links")
ASPxMenu1.Items.Add("Help")

Dim items() As aureports.CatalogItem =
service.ListChildren("/", False)
'Ask how to sort the catalogitem list
For Each item As aureports.CatalogItem In items

If item.Type = aureports.ItemTypeEnum.Folder And Not
(item.Name Like "*_aspx") Then

Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name, item.Path)

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText("Reports")).Items.Add(mitem)
folder(item, mitem, service)

ElseIf item.Type = aureports.ItemTypeEnum.Report And
Not (item.Name Like "*_aspx") And item.Hidden = False Then

Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(item.Name)

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText("Reports")).Items.Add(mitem)

ElseIf item.Type = aureports.ItemTypeEnum.Folder And
item.Name Like "*_aspx" Then

Dim words() As String = Split(item.Name, "_aspx")
Dim mitem As New
DevExpress.Web.ASPxMenu.MenuItem(words(0))

ASPxMenu1.Items.Item(ASPxMenu1.Items.IndexOfText("Services")).Items.Add(mitem)
folder(item, mitem, service)

End If

Next

Cache.Insert(System.Net.CredentialCache.DefaultNetworkCredentials.ToString,
ASPxMenu1)
Else


ASPxMenu1 =
(CType(Cache.Get(System.Net.CredentialCache.DefaultNetworkCredentials.ToString),
ASPxMenu))


End If
End Sub

Public Shared Sub folder(ByVal item As aureports.CatalogItem, ByVal
menu As DevExpress.Web.ASPxMenu.MenuItem, ByVal service As
aureports.ReportingService)

Dim items() As aureports.CatalogItem =
service.ListChildren(item.Path, False)

For Each item2 As aureports.CatalogItem In items
Dim words() As String
words = Split(item2.Name, "_aspx")

Dim itmMenuItem2 As New
DevExpress.Web.ASPxMenu.MenuItem(words(0), "", "", item2.Description)

If item2.Type = aureports.ItemTypeEnum.Folder Then
menu.Items.Add(itmMenuItem2)
folder(item2, itmMenuItem2, service)
ElseIf item2.Type = aureports.ItemTypeEnum.Report And
item2.Hidden = False Then
menu.Items.Add(itmMenuItem2)
ElseIf words.Length > 1 Then
menu.Items.Add(itmMenuItem2)
End If

Next

End Sub

End Class
 
G

Guest

You have a couple of issues that could be improved:

1) use a simpler key for the Cache item - say, the SessionId, which should
not change during the user's session.
2) instead of caching the entire MenuControl, cache only the datasource, and
use that to rebuild your menu.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 
P

poolieweb

Thanks Peter I'll use the session id.

Going to have to think about the menu a little more. as the datasource
is more complicated than just dataset. Ideally I would store an items
collection for the menu but have not found the methods to do this.
Would this not be working due the complexity of the object ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top