I am trying to understand the Simple Spring Memcached but have stuck with below mentioned.
What is the difference between:
Also how does update work. If I make an update on a namespace with a certain key, does it go and execute all read*cache methods within the same namespace and using the same key. If yes, then would it work for multiple server applications.
For example in a certain scenario a user's points(for something) are cached Application 1
@ReadThroughSingleCache(namespace="userPoints")
public Integer getUserPoints(@ParamterKeyValueProvide String userId){
}
In another scenario from a different application(a background scheduler may be) following method is called: Application 2
UpdateThroughSingleCache(namespace="userPoints")
public void updateUserPoints(@ParameterKeyValueProvider String userId, Integer newPoints)
{
//make database update
}
My question is that if the namespace("userPoints") had a cache entry for userId("1234") as 50 points initially and the update method is called with ("1234",100) how would the cache know the logic that the entry for "1234" has to updated with 100 points.
Either it should use the return value and update it with the old value(return type needs to be changed then) or if the update was "write through" the read method should be called with the direct logic of db look up and then updating the cache... but how does application 2 notify application 1 of the update.
There are 3 groups of caching annotations depend on amount of handled keys:
In SSM there is no direct communication between Application 1 and Application 2. To make it work correctly both applications have to use the same Simple Spring Memcached configuration including memcached servers and provider configuration so they will use the same memcached servers. The applications can be deployed on separated servers. When one application put a key to the memcached using ReadThroughSingleCache or UpdateThroughSingleCache the other one can access it while using ReadThroughSingleCache. The signature of update method should be to use method parameter as a new value:
@UpdateThroughSingleCache(namespace="userPoints")
public void updateUserPoints(@ParameterKeyValueProvider String userId, @ParameterDataUpdateContent Integer newPoints)
{
//make database update
}
If you want to use return value to update annotate the method with @ReturnDataUpdateContent.