Class

Cache

tracking.Cache(valueFn)

Represents a cache for a tracked value. It uses a function to find the actual value and caches it. Then as long as none of the Tracked instances it encounters during the execution of the function have not dirtied then the result of this Cache's value remains the same. Only when Tracked instances are dirtied would this re-execute the original function to update the cached value.

This handles auto-tracking which means that while it is executing the function it is keeping track of any Tracked consumed. It then knows which Tracked to check with when it determines if it needs to re-evaluate the cached value.

Constructor

# new Cache(valueFn)

Parameters:
Name Type Description
valueFn function

the function called to update the cached value

View Source tracking.js, line 192

Members

# revision

Properties:
Name Type Description
the number

latest revision number for this Cache

View Source tracking.js, line 240

# value

Properties:
Name Type Description
the any

cached value

View Source tracking.js, line 233

Methods

# static memoize() → {function}

Convenience method to wrap a function in a Cache so that it is memoized.

Properties:
Name Type Description
fn function

the function to be wrapped

View Source tracking.js, line 249

a memoized version of the function

function

# execute() → {any}

Execute the value function if it needs to be updated based on any dependent Tracked it encounters.

View Source tracking.js, line 209

the cached value of the previous execution

any