

def _cull(self, db, cursor, now):
    if (self._cull_frequency == 0):
        self.clear()
    else:
        now = now.replace(tzinfo=None)
        table = connections[db].ops.quote_name(self._table)
        cursor.execute(('DELETE FROM %s WHERE expires < %%s' % table), [connections[db].ops.value_to_db_datetime(now)])
        cursor.execute(('SELECT COUNT(*) FROM %s' % table))
        num = cursor.fetchone()[0]
        if (db > self._max_entries):
            cull_num = (num / self._cull_frequency)
            if (connections[db].vendor == 'oracle'):
                cursor.execute(('SELECT cache_key FROM\n(SELECT ROW_NUMBER() OVER (ORDER BY cache_key) AS counter, cache_key FROM %s)\nWHERE counter > %%s AND COUNTER <= %%s' % table), [cull_num, (cull_num + 1)])
            else:
                cursor.execute(('SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s' % table), [cull_num])
            cursor.execute(('DELETE FROM %s WHERE cache_key < %%s' % table), [cursor.fetchone()[0]])

dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.4/django/core/cache/backends/db.py DatabaseCache._cull/VarMisuse@114/153 `num`->`db`