Spring Boot - 如何在开发期间禁用@Cachable? [英] Spring Boot - How to disable @Cachable during development?

查看:977
本文介绍了Spring Boot - 如何在开发期间禁用@Cachable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找两件事:


  1. 如何使用Spring启动dev配置文件禁用开发期间的所有缓存。在application.properties中,没有seam作为一般设置来关闭它。什么是最简单的方法?

  1. How to disable all caching during development with Spring boot "dev" profile. There doesn't seam to be a general setting to turn it all off in application.properties. What's the easiest way?

如何禁用特定方法的缓存?我试图像这样使用SpEl:

How to disable caching for a specific method? I tried to use SpEl like this:

@Cacheable(value =complex-calc,condition =#{$ {spring.profiles .active}!='dev'})
public String someBigCalculation(String input){
...
}

但我可以让它发挥作用。关于SO的问题有几个问题,但它们是指XML配置或其他东西,但我使用的是Spring Boot 1.3.3,它使用自动配置。

But I can get it to work. There are a couple of questions on SO related to this, but they refer to XML config or other things, but I'm using Spring Boot 1.3.3 and this uses auto-configuration.

我不想让事情过于复杂。

I don't want to over-complicate things.

推荐答案

默认情况下会自动检测缓存的类型,配置。但是,您可以通过将 spring.cache.type 添加到配置中来指定要使用的缓存类型。要禁用它,请将值设置为 NONE

The type of cache is by default automatically detected and configured. However you can specify which cache type to use by adding spring.cache.type to your configuration. To disable it set the value to NONE.

如果您想为特定的配置文件执行此操作,请将其添加到该配置文件 application.properties 在这种情况下修改 application-dev.properties 并添加

As you want to do it for a specific profile add it to that profiles application.properties in this case modify the application-dev.properties and add

spring.cache.type=NONE

这将禁用缓存。

这篇关于Spring Boot - 如何在开发期间禁用@Cachable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆