I have a website that needs to display a "random" selection of items on its homepage. This list is somewhat expensive to generate, so I would like to look into performing some caching that still allows the listing to still appear somewhat random to the untrained eye.
My idea was to use a randomly-chosen number within a given range (let's say 10, for argument's sake) as part of the cache key. Psuedo code would look something like this:
randomCacheVariation = (random number between 1 and 10)
cacheKey = "myRandomList_" + randomCacheVariation
If cache.contains(cacheKey) Then
return existing random list
Else
generate new radom list
add to cache
return list
End If
Does anyone have a better suggestion for how something like this should be implemented?
Update:
Just to be clear, I'm not looking for implementations of caching services, but a strategy of how to cache pseudo-random data by storing some finite number of variations of my list in the cache.