最後,我能夠使用Spring的自定義密鑰生成器支持來解決這個問題。我所做的就是,創建了一個名爲cacheKeyGenearator並分配一個類來它豆,這是實現的KeyGenerator,如:
public class CacheKeyGenerator implements KeyGenerator
{
@override
public String generate(final Object target, final Method method, final Object... params)
String key = "";
// my code to configure key using different params
return key;
}
對XML的一部分,我這樣做:
<cache:annotation-driven key-generator= "cacheKeyGenerator">
<bean id ="cacheKeyGenerator" class ="com.cache.bean"/>
//on my service level
@CacheConfig(keyGenerator="com.cache.bean")
public class cacheServiceImpl implements cacheService
{
@overide
@Cacheable(value="cacheStore")
public String getSurName(String[] name)
// my code
}