A cache boundary chooses between reusing known work and rebuilding fresh output. Modeling the decision keeps the cost tradeoff visible.

Program

Play the script to choose the cache state and see the planned action.

cache_hit
cache_decision_plan.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash

cache_hit=1
if [[ "$cache_hit" -eq 1 ]]; then
    action="reuse"
    cost=1
else
    action="rebuild"
    cost=5
fi
echo "$action cost=$cost"
#!/usr/bin/env bash

cache_hit=0
if [[ "$cache_hit" -eq 1 ]]; then
    action="reuse"
    cost=1
else
    action="rebuild"
    cost=5
fi
echo "$action cost=$cost"
  1. cache_hit ← 1

    3cache_hit=14if [[ "$cache_hit" -eq 1 ]]; then
    values this step1cache_hit
  2. if [[ "$cache_hit" -eq 1 ]]; then

    3cache_hit=14if [[ "$cache_hit" -eq 1 ]]; then5    action="reuse"
    values this step1cache_hit
  3. action ← reuse

    4if [[ "$cache_hit" -eq 1 ]]; then5    action="reuse"6    cost=1
    values this stepreuseaction
  4. cost ← 1

    5    action="reuse"6    cost=17else
    values this step1cost
  5. echo "$action cost=$cost"

    10fi11echo "$action cost=$cost"
    outputreuse cost=1
    values this stepreuseaction1cost
  1. cache_hit ← 0

    3cache_hit=04if [[ "$cache_hit" -eq 1 ]]; then
    values this step0cache_hit
  2. if [[ "$cache_hit" -eq 1 ]]; then

    3cache_hit=04if [[ "$cache_hit" -eq 1 ]]; then5    action="reuse"
    values this step0cache_hit
  3. action ← rebuild

    7else8    action="rebuild"9    cost=5
    values this steprebuildaction
  4. cost ← 5

    8    action="rebuild"9    cost=510fi
    values this step5cost
  5. echo "$action cost=$cost"

    10fi11echo "$action cost=$cost"
    outputrebuild cost=5
    values this steprebuildaction5cost
cache hit A cache hit means previous work can be reused.
cost model A small cost model makes the tradeoff visible without benchmarking.
rebuild path The rebuild path is more expensive but refreshes the output.