Caching data via a typed list... well, kinda

Posts   
 
    
dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 19-Oct-2006 22:57:11   

Hi, I'm using 1.0.2005.1 Final (March 31st 2006), Self Servicing with VS.NET 2003 and SQL Server 2000. I am trying to maintain a cache of data in my application. To do this, I have a singleton class with the following method...

        Public Property AllPeople() As AllPeopleTypedList
            Get
                If mAllPeople Is Nothing Then
                    mAllPeople = New AllPeopleTypedList
                    mAllPeople.Fill()
                End If
                Return mAllPeople
            End Get
            Set(ByVal Value As AllPeopleTypedList)
                mAllPeople = Value
            End Set
        End Property

What I want to do is: whenver a PersonEntity is saved, I want the AllPeople List to be updated with the changes. Should I create a new AllPeopleRow and add it to the list manually every time a new PersonEntity is saved, as well as write code to update existing rows when the corresponding entity is changed? Or is there a better way to do what I am trying to do?

Any help would be greatly appreciated.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 20-Oct-2006 03:15:00   

If you do not want to refetch from the DB on these updates and inserts then you will need to set the readonly property on the typelists columns to false. You can then update them using something similar to this for a typedlist named Test.

test.Columns["Name"].ReadOnly = false;
test[0].Name = "test";

On inserts do just what you said with creating the new row using something like this for a typedlist named Test.

TestRow row = (TestRow)test.NewRow();
row.Name = "Test2";
row.AId = 200;
row.BId = 300;
row.BName = "BTest";
test.Rows.Add(row);
dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 20-Oct-2006 15:34:21   

Thanks Brian, I'll give that a shot. Is there a better way, or is this how you would acomplish this task if you were the developer?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Oct-2006 15:57:49   

I would have refetched from the database after the changed have been saved(INSERTS/UPDATES). Since this would make sure that the cashed data are an exact copy of what's in the database, espesially if you some fields get set inside the DB (fields using DB Default Values, or Set by some triggers)

dazedorconfused avatar
Posts: 89
Joined: 06-Apr-2006
# Posted on: 20-Oct-2006 16:37:53   

To refetch, would I just call fill on the typed list again?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 21-Oct-2006 02:48:22   

yes, that's all you have to do.