Distributed cache and improvement
Posted
by
philipl
on Programmers
See other posts from Programmers
or by philipl
Published on 2012-06-16T05:49:27Z
Indexed on
2012/07/10
3:22 UTC
Read the original article
Hit count: 208
caching
Have this question from interview:
Web Service function given x
static HashMap map (singleton created)
if (!map.containsKey(x)) {
perform some function to retrieve result y
map.put(x, y);
}
return y;
The interviewer asked general question such as what is wrong with this distributed cache implementation. Then asked how to improve on it, due to distributed servers will have different cached key pairs in the map.
There are simple mistakes to be pointed out about synchronization and key object, but what really startled me was that this guy thinks that moving to database implementation solves the problem that different servers will have different map content, i.e., the situation when value x is not on server A but on server B, therefore redundant data has to be retrieved in server A. Does his thinking make any sense? (As I understand this is the basic cons for distributed cache against database model, seems he does not understand it at all)
What is the typical solution for the cache growth issue (weak reference?) and sync issue (do not know which server has the key already cached - use load balancing)?
Thanks
© Programmers or respective owner