In an enlightening blog post, Ramon Leon explains that most applications are designed for small businesses with small amounts of data. Therefore most applications will never have to scale (i.e. become the next Twitter), so a relational database is overkill. However, persisting by simply saving the image is slow and error-prone.
Based on these ideas, he suggests a simple (one class) framework which saves only your model. The idea is to use it as long as you can get away with, which may be forever.
I packaged the code from the post, added a few tests, and put it on SqueakSource as SimplePersistence.
It’s really easy to give your application persistence (see SPFileDatabase’s class comment). The three steps are:
- Subclass SPFileDatabase
- On the class-sode of the subclass, implement
- #repositories – returns a collection of objects to be saved
- #restoreRepositories: – gets passed back the collection.
That’s it! Now, whenever you want to save, call class>>saveRepository or class>>takeSnapshot (background save).