is_cached(obj, cache) that returns True if obj is the exact same object (not merely an equal value) as any item currently in the list cache, using the is identity operator. This models a cache that stores object references and must distinguish "same instance" from "equal value" (e.g. two equal-looking dicts loaded separately should NOT count as cached).x = {"id": 1}; cache = [x]; is_cached(x, cache)True
x is literally the object stored in cache.
is_cached({"id": 1}, [{"id": 1}])False
Equal values but distinct object instances — not a cache hit.
Loop through cache and check `item is obj` for each, not `item == obj`.
The built-in `any()` combined with a generator expression can shorten this.