Inside StorageLists

When I began writing the back end for After, I started with Entity Framework/SQL Server.  I wanted to use the opportunity to teach myself the Code-First approach, as I’ve previously only done Database-First.

I really enjoyed working with Code-First, and it was a worthwhile investment of time.  However, I soon found that  SQL Server isn’t well-equipped to handle multiple persistent connections that need to share a static context.  (Please refrain from saying, “Duh, I could have told you that!”  :D)

Instead of searching for something else, I decided to get creative and write my own.  I already had my data modeled in such a way that I could reference everything by ID/PK, and I liked how Code-First used the DbContext class and DbSets.  So I put those concepts into StorageLists.

The StorageList is basically a List<> that writes items to disk after a set period of time of not being accessed.  This timeout can be adjusted, but the default is 3 minutes.  Also, the item must pass the PersistenceFilter, if specified, or else is held in memory and never written to disk.  Items written to disk are serialized to JSON.

Your models for each StorageList must implement IStorageItem, which adds the StorageID property and LastAccessed.

Here’s the example use that’s in the readme:

 

Leave a Reply

Your email address will not be published. Required fields are marked *