Book Image

Mastering Object-oriented Python

By : Steven F. Lott, Steven F. Lott
Book Image

Mastering Object-oriented Python

By: Steven F. Lott, Steven F. Lott

Overview of this book

Table of Contents (26 chapters)
Mastering Object-oriented Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Some Preliminaries
Index

The writeback alternative to index updates


We can request that a shelf be opened with writeback=True. This will track changes to mutable objects by keeping a cached version of each object. Rather than burdening the shelve module with tracking all accessed objects to detect and preserve changes, the designs shown here will update a mutable object and specifically force the shelf to update the persistent version of the object.

This is a small shift in the runtime performance. An add_post() operation, for example, becomes slightly more costly because it also involves updating a Blog entry. If multiple Posts are added, these additional Blog updates become a kind of an overhead. However, this cost may be balanced by the improved performance of rendering Blog by avoiding a lengthy search of the shelf keys to track down the posts for a given blog. The designs shown here avoid creating a writeback cache that could grow unbounded during the running of an application.

Schema evolution

When working with...