from pylons import app_globals as g

from r2.models import PromoCampaign

class PromoCampaignByFlightIdCache():
    @classmethod
    def _cache_key(cls, flight_id):
        return "flightid:%s" % flight_id

    @classmethod
    def add(cls, campaign):
        key = cls._cache_key(campaign.external_flight_id)
        g.gencache.set(key, campaign._fullname, time=60*60*24)

    @classmethod
    def get(cls, flight_id):
        fullname = g.gencache.get(cls._cache_key(flight_id))

        if not fullname:
            q = PromoCampaign._query(
                PromoCampaign.c.external_flight_id == flight_id,
                data=True,
            )
            q._limit = 1
            campaigns = list(q)
            if campaigns:
                campaign = campaigns[0]

                cls.add(campaign)

                return campaign._fullname
            else:
                return None
        else:
            return fullname

@@ -472,16 +472,28 @@
 ight_id)
+, stale=True
 )%0A%0A     
@@ -619,35 +619,8 @@
 id,%0A
-                data=True,%0A
     

Use stalecache