[Answered ]-Memcached vs. database for random select

2👍

Store them in the database with sequential id numbers and then simply pick a random number between 0 and the number of keys then check memcached for the key, if it returns the question use it if not pull it from the database and put it in memcached for the next use.

This will run you into problems if you delete questions and so there are missing IDs in the sequence but this problem can be overcome, for example, if instead of using IDs you instead select the X item in the database and then when the questions do change you clear memcached so the data gets refreshed.

Leave a comment