(self, sql, types)
return plan
Prepare the plan and cache it.
Prepare the plan and cache it.
Prepare the plan and cache it .
def get_plan(self, sql, types):
        """Prepare the plan and cache it."""

        t = (sql, tuple(types))
        if t in self.plan_map:
            pc = self.plan_map[t]
            # put to the end
            self.plan_list.remove(pc)
            self.plan_list.append(pc)
            return pc.plan

        # prepare new plan
        plan = plpy.prepare(sql, types)

        # add to cache
        pc = CachedPlan(t, plan)
        self.plan_list.append(pc)
        self.plan_map[t] = pc

        # remove plans if too much
        while len(self.plan_map) > self.maxplans:
            pc = self.plan_list.pop()
            del self.plan_map[pc.key]

        return plan
def get_plan ( self , sql , types ) : t = ( sql , tuple ( types ) ) if t in self . plan_map : pc = self . plan_map [ t ] # put to the end self . plan_list . remove ( pc ) self . plan_list . append ( pc ) return pc . plan # prepare new plan plan = plpy . prepare ( sql , types ) # add to cache pc = CachedPlan ( t , plan ) self . plan_list . append ( pc ) self . plan_map [ t ] = pc # remove plans if too much while len ( self . plan_map ) > self . maxplans : pc = self . plan_list . pop ( ) del self . plan_map [ pc . key ] return plan