title: possible to cache a table in sqlalchemy to not query database in specific use case?
body: <p>I have a use case where I am running a python script constantly updating a specific column on a table in a database.  The script is like the following:</p>
  <pre><code>while True:
      events = load_events()
      for event in events:
          team_1 = event.team_1
          team_2 = event.team_2
          dd = datetime.strptime(event.gametime, &quot;%Y-%m-%dT%H:%M:%S.000Z&quot;)
          begin = dd - timedelta(hours=4)
          end = dd + timedelta(hours=4)
  
          db_event = session.query(SportEvent).filter(and_(
              SportEvent.home_team.contains(event.team_1),                                      
              SportEvent.away_team.contains(event.team_2),
              SportEvent.game_time.between(begin, end))).first()
          if db_event.e_id != event.event_id:
              setattr(db_event, 'e_id', event.event_id)
      session.commit()
  </code></pre>
  <p>My problem is that each loop takes far longer than is acceptable because I am updating 100k events.  I want to implement some sort of snapshot or cache at the start of each loop so each query to <code>SportEvent</code> doesn't actually produce a query on the database, but rather just  check against the cache.  (I understand the risks of this and they are acceptable for my use case in how this table is updated/accessed as a whole).  How can I implement something like this?</p>
  <pre><code>class SportEvent(Base):
      __tablename__ = 'sport_events'
  
      id = Column(String, primary_key=True)
      sport_id = Column(String)
      league_id = Column(String)
      away_team = Column(String)
      home_team = Column(String)
      game_time = Column(DateTime)
      dk_id = Column(String)
      fd_id = Column(String)
      cs_id = Column(String)
      bm_id = Column(String)
  
      def __init__(self, home_team=None,
                   away_team=None,
                   game_time=None, sport_id=None, league_id=None):
          self.id = uuid.uuid4()
          self.home_team = home_team
          self.away_team = away_team
          self.game_time = game_time
          self.sport_id = sport_id
          self.league_id = league_id
          self.dk_id = &quot;&quot;
          self.fd_id = &quot;&quot;
          self.cs_id = &quot;&quot;
          self.bm_id = &quot;&quot;
  </code></pre>