anymodel.utilities.identity_map

Identity map implementation for preventing duplicate entity instances.

This module provides the IdentityMap class which ensures that only one instance of an entity with a given identity exists in memory at a time.

Classes

class anymodel.utilities.identity_map.IdentityMap[source]

Bases: object

Maintains a single instance per entity identity.

Uses weak references to allow garbage collection of entities that are no longer referenced elsewhere in the application.

__init__()[source]
set(key, entity)[source]
get(key)[source]
Return type:

Entity | None