views:

50

answers:

1

I'm looking for a effective and scalable way of doing the following with the java low level API. I have a query with some sort orders and i would like to fetch the Nth entity. Using the offset argument doesn't seem like a good idea.

EDIT Background: I'm trying to write an abstraction layer for DS with a Memcache. The data stored in the datastore should be arbitrary. Examples of methods: getEntity(key) AddEntity(entity) getEntityByIndex(index, sort)

Any suggestions are appreciated.

A: 

Using an offset is the only way to do this if the only information you have is the index of the element. As you observe, this isn't efficient (on any database, not just the Datastore).

Depending on your situation, though, you may be able to use an alternate solution, such as datastore cursors.

Nick Johnson
No i don't have access to anything but the sort orders and the index of the entity.I've thought about using cursors. My idea is to uphold an index of cursors for some every ith interval say 100,200... in memcache. So eg. to get the 220th element I would check memcache for pointer at 200 and fetch 100 entities(need to cache those anyways) and return element nr 20 in that result. After this fetch I could cache the pointer pointing to 300.One major problem is that adding even a single entity would invalidate all pointers. So I'm wondering if there is any performance gains.Comments?
Can you provide some background on what you're trying to do, and what your constraints are?
Nick Johnson
I tried to give some background above. Does it make more sense now?