Skip to content

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. #20

@DYAI2025

Description

@DYAI2025

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions