.net - Storing subcollections (filtered versions of the main collection) inside the collection as cache? -
is practice store sub-collections of item x inside parent collection of item x caching 'filter-queries' performed on parent collection? (they won't used (as in color , type).) or ok loop on collection , return correct entities in temporary collection?
class itemcollection : inherits collection(of item) private _types new list(of itemcollection) //cache function filterbytype(type) itemcollection if not _types.keyexists(type) _types.add(type, new itemcollection()) each in me if i.type = type _types(type).add(i) next end if return _types(type) end function //same filterbycolor(color) end class class item public color = "blue" public [type] = "one" end class
i recommend keeping simple start , add caching if testing shows regenerating filtered lists performance problem. besides that, filtering code can simplified using filtering methods built list or using linq extensions.
filtered = me.where(i => i.type = type)
(i off on exact syntax, i've never done linq in vb.net, i'm c# guy.)
Comments
Post a Comment