Storing mutable data directly in the cache without copying can lead to cache corruption. If the caller modifies the data structure after it's been cached, the cache will contain the modified data.
For example:
data = {"session_id": "123", "patterns": []}
bridge._set_cached_value("test", data)
data["patterns"].append({"new": "pattern"}) # Modifies cached data!
Consider storing a deep copy to prevent external modifications from affecting the cache:
import copy
self._cache[key] = {"timestamp": time.time(), "data": copy.deepcopy(value)}
Originally posted by @Copilot in #17 (comment)
Storing mutable data directly in the cache without copying can lead to cache corruption. If the caller modifies the data structure after it's been cached, the cache will contain the modified data.
For example:
Consider storing a deep copy to prevent external modifications from affecting the cache:
Originally posted by @Copilot in #17 (comment)