How to cache a built panel bar?

4 posts, 0 answers
  1. Jason
    Jason avatar
    3 posts
    Member since:
    Jan 2009

    Posted 07 Apr 2010 Link to this post

    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.


  2. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 08 Apr 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jason
    Jason avatar
    3 posts
    Member since:
    Jan 2009

    Posted 08 Apr 2010 Link to this post

    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.

  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 15 Apr 2010 Link to this post

    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.
Back to Top