cache.js
/*      problem/
 * We don't want to re-process the
 * log records again and again
 * evertime a new record is
 * appended.
 *
 *      way/
 * We realize that most records are
 * added to the end of the log.
 * This, combined with the fact that
 * log processing is memoizable,
 * allow us to simply cache the last
 * record of the log. If the record
 * remains in the same place all
 * the new records are after it and
 * processing can start after this
 * point.
 * If, on the other hand, the record
 * is not in the same place then
 * some records have been inserted
 * into the log and so we discard
 * the entire cache and start
 * processing from the beginning
 * again.
 */
problem
We don't want to re-process the
log records again and again
evertime a new record is
appended.

way
We realize that most records are
added to the end of the log.
This, combined with the fact that
log processing is memoizable,
allow us to simply cache the last
record of the log. If the record
remains in the same place all
the new records are after it and
processing can start after this
point.
If, on the other hand, the record
is not in the same place then
some records have been inserted
into the log and so we discard
the entire cache and start
processing from the beginning
again.
problem We don ' t want to re - process the log records again and again evertime a new record is appended . way We realize that most records are added to the end of the log . This combined with the fact that log processing is memoizable allow us to simply cache the last record of the log . If the record remains in the same place all the new records are after it and processing can start after this point . If on the other hand the record is not in the same place then some records have been inserted into the log and so we discard the entire cache and start processing from the beginning again .
function cachedUpto(logname, recs, cache) {
    let recndx = recs.length-1
    let rec = recs[recndx]
    cache[logname] = {
        recndx: recndx,
        rec: rec,
    }
}
function cachedUpto ( logname , recs , cache ) { let recndx = recs . length - 1 let rec = recs [ recndx ] cache [ logname ] = { recndx : recndx , rec : rec , } }
problem
 We don't want to re-process the
 log records again and again
 evertime a new record is
 appended.
problem We don ' t want to re - process the log records again and again evertime a new record is appended .