У меня есть класс Page
и класс PageCollection
в среде ORM для сторонних разработчиков. Я могу заполнить PageCollection на основе параметров (pageid, parentid, url и т. Д.) (SQL-запрос). Но мне нужны данные несколько раз на веб-сайте ASP.NET MVC (Sitemap, Authentication), поэтому я решил загрузить все страницы 1 раз и сослаться на эту (глобальную) коллекцию.
GlobalClass.Pages //is PageCollection containing all pages
Я создал функции, которые возвращают временную вложенную коллекцию или отдельную сущность на основе параметров, упомянутых ранее (pageid, parentid, url и т. Д.).
GlobalClass.Pages.GetByPageId(id) //returns single page entity
GlobalClass.Pages.GetByParentId(parentid) //returns subcollection
Однако сайт стал очень медленным.
Какой путь сюда?
- кэшировать подколлекции (
GetByParent()
) ?
- создание внутренних таблиц хеш-поиска для коллекции ?
- Что-то еще ... ?
Namespace BLL
Public Class PageCollection
Inherits CustomCollectionBase
Public Sub New()
End Sub
Public Sub LoadByParent(ByVal PagParent As Integer)
If PagParent = 0 Then
Me.whereAdd('parent IS NULL')
Else
Me.whereAdd('parent = ' & PagParent.ToString())
End If
Me.Load(Me.data)
End Sub
Public Function GetBySiteMapNode(ByVal node As SiteMapNode) As BLL.Page
Return Me.GetByUrl(node.Url)
End Function
Public Function GetById(ByVal id As Integer) As BLL.Page
For Each p In Me
If p.PagAutoKey = id Then Return p
Next
Return Nothing
End Function
Public Function GetByUrl(ByVal url As String) As BLL.Page
For Each p In Me
If p.Url = url Then Return p
Next
Return Nothing
End Function
Public Function GetByParent(ByVal parent As Integer) As BLL.PageCollection
Dim pc As New PageCollection
For Each p In Me
If p.PagParent = parent Then pc.Add(p)
Next
Return pc
End Function
End Class
End Namespace