title: Google App Engine : Cursor Versus Offset
body: <p>Do you know which is the best approach for fetching chunks of result from a query?</p>
  
  <h1>1.Cursor</h1>
  
  <pre><code>q = Person.all()
  last_cursor = memcache.get('person_cursor')
  if last_cursor:
      q.with_cursor(last_cursor)
  people = q.fetch(100)
  cursor = q.cursor()
  memcache.set('person_cursor', cursor)
  </code></pre>
  
  <h1>2.Offset</h1>
  
  <pre><code>q = Person.all()
  offset = memcache.get('offset')
  if not offset:
     offset = 0
  people = q.fetch(100, offset = offset)
  memcache.set('offset', offset + 100)
  </code></pre>
  
  <p>Reading the <a href="http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Query_Cursors" rel="noreferrer">Google documentation</a>, it seems that Cursor does not add the <strong>overhead</strong> of a query offset.</p>