Fixpoint cache_lookup (C: cache) (t: term) : term :=
match t with
| var _       => t
| capply c lt => capply c (map (cache_lookup C) lt)
| fapply f lt => match assoc_cache (fapply f (map (cache_lookup C) lt)) C with
| Some v => @term_from_value _ _ _ v
| None   => t
end
end.

Lemma cache_lookup_value (C: cache) (v: value):
let t := @term_from_value _ _ _ v in cache_lookup C t = t.