私はアノテーションを使用して私のプロジェクトでスプリングキャッシングを使用しています。プロファイルに基づいて私はElasticacheとSimpleCacheManagerを使用しています。使用注釈は、私はどこでも私は好まないどのハードコードキャッシュ名「MyCacheという」に強制していますスプリングキャッシングとハードコードされたキャッシュ名
//For the initial configuration settings in some class when profile is cloud.
@EnableElastiCache({@CacheClusterConfig(name = "MyCache", expiration = 86400)})
// For the initial configuration settings in some class when profile is non-cloud.
SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
simpleCacheManager.setCaches(newArrayList(new ConcurrentMapCache("MyCache")));
@CacheConfig(cacheNames = {"MyCache"})
public class CachingRequiredClass{
........
@Cacheable
public String blablaMethod(String id){
.....
}
}
public class SomeOtherClass{
......
@Caching(evict={
@CacheEvict(value="MyCache", key="T(com.myclass).myMethod()+':blablaMethod()'"),
@CacheEvict(value="MyCache", key="T(com.myclass).myMethod()+':blablaMethod()+':blablabla2Method()'")
})
public void logout(){
......
}
}
です。これを構成可能にする方法はありますか?どういうわけかプロパティファイルから来ますか?
提案していただきありがとうございます。私はSpELの方法で試してみます。キャッシュのクエリの質問については、私はcom.myclass.myMethod()を呼び出すときにいくつかのユーザー固有のIDを返すキージェネレータを持っています。だからそれに基づいて追い払う。 – paramupk
それは私がIMOを書いたものを変更しません。キャッシュを手動で操作する場合は、キーにメソッドの名前を含めないでください。物事があなたのために行われたら、それをしないでください、それは起こっていることを理解することが難しくなります。 –