This is a migrated thread and some comments may be shown as answers.

How to cache a built panel bar?

3 Answers 61 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 08 Apr 2010, 12:56 AM
I have a panel bar that is built up of some pretty expensive database queries, I don't want this binding to happen per page load.

In my code I build up the panel using allocated RadPanelItems(), and than I was planning to allocate a RadPanelItemCollection() to put all the items into.  Then I would only have to cache that Item Collection once across the site, and just assign it to the Items property of the RadPanel...  But you can't do that.

The collection can only be constructed with a parent control, and once a control is built you can't assign a collection to it (get, no set).

How are you supposed to cache the items list in a RadPanel?  I don't want it to have to cache per user, and I don't want to have the bind happen over and over.

Thanks.


3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 08 Apr 2010, 01:14 PM
Hi Jason,

RadPanelItemCollection supports the AddRange method which accepts an array of RadPanelItem objects. If you cache the Items to the latter you can use it with the former, e.g.
RadPanelItem[] cachedItems = ...;
RadPanelBar1.Items.AddRange(cachedItems);

Isn't this useful?

Kind regards,
Simon
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jason
Top achievements
Rank 1
answered on 08 Apr 2010, 05:16 PM
Yes, that is very useful.  Thanks for that information.

But I still only Get the ItemsCollection, not an array of items.  And there is no ToArray on the collection.  So I guess I will just have to build it up by hand.

It would be more useful as an API I think to allow the ItemsCollection to be created and then assigned to a RadPanel.Items through a setter.  That is how most .Net controls work.

So in this case I would need to do something like this:

        RadPanelItemCollection panelCollection = RadPanelBar1.Items; 
        RadPanelItem[] itemlist = new RadPanelItem[RadPanelBar1.Items.Count]; 
        int i = 0; 
        foreach (RadPanelItem pi in panelCollection) 
        { 
            itemlist[i++] = pi; 
        } 
 

That would give me the itemlist, and then to re-hydrate a new RadPanelBar I would use the AddRange member.

I tested this and it works fine.  The original time to build the RadPanelBar including all round trips to DB is 850 ms.  To rebuild it from the AddRange was 12 ms.  Lot faster.

0
Kalina
Telerik team
answered on 15 Apr 2010, 09:26 AM
Hello Jason,

I am afraid that storing controls or collections of control items is not a good practice - please take a look at this blog article. In fact cached controls or items collections store a reference to the page and this can cause memory leak.

I recommend you try another approach - create custom class ItemData,  add the data ( Value, NavigateUrl etc.) from the items to this class, cache it and then use it for databinding.


Greetings,
Kalina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
PanelBar
Asked by
Jason
Top achievements
Rank 1
Answers by
Simon
Telerik team
Jason
Top achievements
Rank 1
Kalina
Telerik team
Share this question
or