【发布时间】:2019-03-16 07:19:18
【问题描述】:
我使用的是 spring-boot-starter-parent 2.0.1 版
这些是 application.properties
spring.cache.type=redis
spring.cache.cache-names=edges
spring.cache.redis.cache-null-values=false
spring.cache.redis.time-to-live=60000000
spring.cache.redis.key-prefix=true
spring.redis.host=localhost
spring.redis.port=6379
这是主类。
@SpringBootApplication
@EnableAsync
@EnableCaching
public class JanusApplication {
public static void main(String[] args) {
SpringApplication.run(JanusApplication.class, args);
}
}
这是我要缓存它的结果的java方法。
@Service
public class GremlinService {
@Cacheable(value = "edges")
public String getEdgeId(long fromId, long toId, String label) {
// basically finds an edge in graph database
}
public Edge createEdge(Vertex from, Vertex to, String label){
String edgeId = getEdgeId((Long) from.id(), (Long) to.id(), label);
if (!Util.isEmpty(edgeId)) {
// if edge created before, use its id to query it again
return getEdgeById(edgeId);
} else {
return createNewEdge((Long) from.id(), (Long) to.id(), label);
}
}
}
我没有任何其他的 redis 或缓存配置。虽然它不会抛出任何错误,但它不会缓存任何东西。我用redis-cli检查。
【问题讨论】:
-
嗨,您能否更新一下您在代码中如何/在何处调用
getEdgeId(...)方法的问题? -
你好,我已经更新了
-
谢谢。正如古斯塔沃帕西尼所写。这是因为您从同一个班级调用它。将缓存的方法移动到另一个类。
标签: spring-boot spring-data-redis spring-cache