Altering queries?

K J sanbat at
Fri Sep 21 08:12:22 UTC 2007

> Only you could answer that definitively, but I would guess that it would
> be better to get the lot.  Depends how often your data changes.
> On my site, people see the first 15 entries, but I put the first 100 in
> one cache key, and the first 500 in a second cache key if needed.  I get the
> first 15 out of the hundred, and if they want more, I iterate though it
> until I need more than 100.  On the rare occassion that anyone gets past the
> 500 mark I just go straight to the database, and then add back to the
> cache.
> I've split it up into 100 and 500 because most people would only ever look
> at less than the first 100 entries.  if they do manage to look past the
> first 100, then I have the first 500 cached in another key.  Keep in mind,
> this is not first 100 next 500 to make a total of 600 articles.  The first
> 100 are also duplicated in the 500 list.  The 500 entry list is generated
> only the first time it is needed, and the exact same routine also creates
> the 1000 entry key if that is ever needed, and so on.  There is no built in
> limit, it could end up being a key for a 20000 entry list fall all I know.
> Every situation is different.  I suggest you build some test cases and
> test it under various situations and see what works for you.  There are some
> parts of my site that dont use memcache at all and simply go to the database
> directly every time, but I did it that way because for that particular
> problem a cached solution would be clunky, and memcache just didnt fit
> well.  But apart from those special cases, I cache almost everything.  I
> cache the little bits of data (such as key for each IP address that hits the
> site, I increment a counter each time they hit, and give it an expiry), all
> the small elements of data, all the bigger elements made up of the smaller
> elements, all the rendered XML and some of the rendered HTML.  My database
> is mostly idle :)

I'm wondering about the 100, then the 500.  Are you creating a new array at
certain intervals? For instance suppose a user keeps paging through the
results and end up at result 800.  Would you then have 3 arrays like this?
- 100 array
- 500 array
- 1000 array
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the memcached mailing list