There are 3 groups of caching annotations depend on amount of handled keys:
- *AssignCache - the cache key is constant and doesn't depends on method's parameters, usually used on method without parameter i.e. getAllUsers()
- *SingleCache - the cache key is created using annotated method's parameters, result is stored under single key, method's parameter of type List cannot be used to generate cache key
- *MultiCache - the cache is created using annotated method's parameters, exactly one of the parameter has to be of type List, result also has to be a List, each element from the result List is stored under dedicated cache key
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.