Cache objects
The 1-wire bus is slow. A single query takes at least a few milliseconds. Temperature measurements can take as long as 1000 milliseconds. Computer memory is much faster (microseconds). Even network communication is faster
There are three ways around the problem:
- Ask for the data early, and do other work while it's being obtained.
- Remember the value in your program, but also remember when the data is stale.
- Let OWFS cache the data, removing it when it gets beyond a specified age.
Here is a picture of the OWFS cache. Held in memory as a Binary Tree (for quick searching). The cache grows dynamically, storing various types of 1-wire data.
The types of stored objects include:
- device presence (and bus)
- directory lists
- properties.
Device properties can be either
- volatile items that change on their own (like measured temperature), or
- stable values, like alarm limits or memory contents.
Typically, we would time out the volatile properties more quickly.
When a value gets too old, it expires. Trying to read the 22.BB02/temperature value will trigger another 1-wire query, and the cache will be updated with the new value. Your program doesn't need to worry about the details.
Uncached
At any point, you can request a direct 1-wire read by looking at the /uncached directory (e.g. /uncached/28.CC03/temperature). That new value wil be placed in the cache as well, perhaps updating an existing reading.
Previous page: Cache design
Next page: Cache flip