Preference Caching and Synchronization

Preference Services uses caching in order to improve read and write performance. In other words, when you call CFPreferencesSetAppValue , Preference Services saves the new value in your application's cache, but doesn't write it to permanent storage. Subsequent preference searches will find the new value, but you must call CFPreferencesAppSynchronize to flush the cache to permanent storage.

Preferences are cached on a per-application basis and so, in certain rare circumstances, it is possible for your application to retrieve a stale preference value from its cache. For example, when you read from a given preference domain, the value is stored in your application's cache. If for some reason another application writes to that same domain, your application does not see the new value. This is extremely unlikely to occur in the context of a single application, and in general, applications should not consider retrieving a stale value to be catastrophic.

It is somewhat more likely for applications using suite preferences to read stale values because the applications are writing to a shared domain. Even here, you should ask whether it's truly a problem for an application to pick up a stale value. If not, there is no reason make an extra effort to synchronize before and after every preferences access.

When considering this issue, it is important to understand that synchronizing is expensive, and so should be done only rarely. In general, you should only synchronize when your application quits, and also perhaps when a preference dialog is dismissed. Synchronizing causes several file accesses, some of which may be across the network, and could take as long as several seconds to complete. Unless an application absolutely cannot handle picking up a stale value, it should never synchronize on read.


© 2000 Apple Computer, Inc. (Last Updated 14 July 2000)