@db.listens_for(db.Session, "after_flush")
def store_purge_keys(config, session, flush_context):
    cache_keys = config.registry["cache_keys"]

    # We'll (ab)use the session.info dictionary to store a list of pending
    # purges to the session.
    purges = session.info.setdefault("warehouse.cache.origin.purges", set())

    # Go through each new, changed, and deleted object and attempt to store
    # a cache key that we'll want to purge when the session has been committed.
    for obj in (session.new | session.dirty | session.deleted):
        try:
            key_maker = cache_keys[obj.__class__]
        except __HOLE__:
            continue

        purges.update(key_maker(obj).purge)
dataset/ETHPy150Open pypa/warehouse/warehouse/cache/origin/__init__.py/store_purge_keys