Reputation: 9574
I need to design a cache for storing objects coming in from multiple clients. These clients can all come in parallel. These objects need to stored on memcached, and retrieved later for use.
String newKey ;
private synchronized String setData(Data newData) {
do {
newKey = createRandomKey() ;
} while (memcacheClient.get(newKey) != null) ;
memcacheClient.set(newKey, 10000, newData) ;
}
My question is, will this method become a bottleneck for parallel client access ?
OR
Should I create a shared List and a Thread. The thread will do the setData, asynchronously ?
Upvotes: 1
Views: 187
Reputation: 411
The delay of the loop heavily depends on how random createRondomKey can achieve. Do you have to use random keys? Is it possible to come up with some semantic naming schemes (e.g., userid/category/blabla)? That will also save you the efforts to remember the random keys.
Upvotes: 1