【发布时间】:2016-10-13 22:58:12
【问题描述】:
我正在通过http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html 将 Spring Cache 集成到我们的 AWS 应用程序中。
有人可以向我解释如何使用指南正确封装不同的@Cacheable 类吗?
据我所知,当您使用@EnableElastiCache 时,您需要在注释中指定在 AWS 中创建的 Elasticache 集群的名称:
@EnableElastiCache( @CacheClusterConfig( name = "myAwsCluster", expiration = 300 ) )
那么您必须使用与@Cacheable 类中的缓存名称相同的集群名称:
@Cacheable( "myAwsCluster" )
public String expensiveMethod()
除非我遗漏了什么,否则这会完全破坏封装,因为您必须将注释上的值与您在 AWS 中创建的物理资源联系起来。是我遗漏了什么,还是 Spring Cloud 期望您的工作方式?
此外,这意味着您需要为要使用的每个春季 Cache 类启动一个单独的 AWS ElastiCache 集群,这使得它非常昂贵并禁止资源共享。
@CacheConfig( "myAwsCluster" )
public class Class1
{
@Cacheable
public void something()
{
...
}
}
@CacheConfig( "mySecondAwsCluster" )
public class Class2
{
@Cacheable
public void somethingElse()
{
...
}
}
【问题讨论】:
-
您找到解决方案了吗?
-
老实说,我不记得了——这可能意味着我没有找到解决方案。我认为这是一个简短的研究问题,并没有走得太远(否则我可能会记得)
-
对于类似情况的人,我已经添加了答案
标签: amazon-elasticache spring-cache