def cached_objects_with_updates(iter):
    """Return objects from a session/iterator that are tagged for caching and
    that need an update."""
    for obj in iter:
        if getattr(obj, '__needs_update__', False):
            yield obj
