Я работаю с Apache Camel в Quarkus и включаю удаление кеша через определенное время, но я не могу его удалить, т.е. Я использую свойства Camel.comComponent.caffeine-cache.expire-after-access-time и Camel.comComponent.caffeine - кэш .expire-after-write-time в свойствах, однако я тестирую и после установки времени 60 секунд запрос все равно выполняется в кеше:
#cache
camel.component.caffeine-cache.expire-after-write-time=60
camel.component.caffeine-cache.expire-after-access-time=60
Тест номер 1 в 14:00:
Запросить кеш:
CamelCaffeineActionHasResult = true
Тест номер 2 в 14:04, в этом хаосе уже прошло 240 секунд с момента его кэширования:
Продолжайте сверяться с кешем:
CamelCaffeineActionHasResult = true
Что может быть причиной такого поведения? Разве нельзя будет снова обратиться к сервису за пределами кеша после истечения срока действия (60 секунд)?
Вот как я настроил свой ResRoute
@ApplicationScoped
public class ResRoute extends RouteBuilder {
@ConfigProperty(name = "client.findIndividualCustomerByDocId")
String findIndividualCustomerByDocId;
@ConfigProperty(name = "client.findOrganizacionCustomerByDocId")
String findOrganizacionCustomerByDocId;
@ConfigProperty(name = "path.openapi")
String pathOpenapi;
@ConfigProperty(name = "descripcion.servicio")
String descripcionServicio;
private ConfigureSsl configureSsl;
private static final String SALIDA_BSS_EXCEPTION = "Salida del microservicio BSS FindCustomerByDocId ${exchangeProperty[bodyRs]}";
private static final String MSG_EXCEPTION = "Descripcion de la Exception: ${exception.message}";
public ResRoute() {
configureSsl = new ConfigureSsl();
}
@Override
public void configure() throws Exception {
BeanDate beanDate= new BeanDate();
getContext().getRegistry().bind("BeanDate",beanDate);
restConfiguration()
.bindingMode(RestBindingMode.json)
.dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES")
.apiContextPath(pathOpenapi)
.apiProperty("api.title", "FindCustomerByDocId")
.apiProperty("api.description", descripcionServicio)
.apiProperty("api.version", "1.0.0")
.apiProperty("cors", "true");
rest("customerInformation/v1.4.0/users/")
.get("/{user_id}/customers").to("direct:/{user_id}/customers")
.outType(Customer.class)
.param().name("FindCustomerByDocIdResponse").type(body).description("parametro de salida").required(true)
.endParam()
.to("direct:pipeline");
from("direct:pipeline")
.doTry()
.process(new FindCustomerByDocIdProcessorReq())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"User ID: ${exchangeProperty[userId]}")
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Correlator ID: ${exchangeProperty[correlatorId]}")
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Tipo de Documento (Num): ${exchangeProperty[documentTypeNum]}")
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Tipo de Cliente: ${exchangeProperty[customerType]}")
.choice()
.when(simple("${exchangeProperty[customerType]} == 'NATURAL'"))
.process(new FindIndividualCustomerByDocIdProcessorReq())
.setHeader(CaffeineConstants.ACTION, constant(CaffeineConstants.ACTION_GET))
.setHeader(CaffeineConstants.KEY).exchangeProperty("documentNumber")
.toF("caffeine-cache://%s", "IndividualCache")
.log("Hay Resultado en Cache de la consulta asociado al siguiente documento: ${exchangeProperty[userId]} ${header.CamelCaffeineActionHasResult}}")
.log("CamelCaffeineActionSucceeded: ${header.CamelCaffeineActionSucceeded}")
.choice().when(header(CaffeineConstants.ACTION_HAS_RESULT).isEqualTo(Boolean.FALSE))
.to(configureSsl.setupSSLContext(getCamelContext(), findIndividualCustomerByDocId))
.setHeader(CaffeineConstants.ACTION, constant(CaffeineConstants.ACTION_PUT))
.setHeader(CaffeineConstants.KEY).exchangeProperty("documentNumber")
.toF("caffeine-cache://%s", "IndividualCache")
.process(new FindIndividualCustomerByDocIdProcessorRes())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio FindIndividualCustomerByDocId ${exchangeProperty[findIndividualCustomerByDocIdResponse]}")
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio BSS FindCustomerByDocId ${exchangeProperty[findCustomerByDocIdResponse]}")
.otherwise()
.log("Cache is working")
.process(new FindIndividualCustomerByDocIdProcessorRes())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio FindIndividualCustomerByDocId ${exchangeProperty[findIndividualCustomerByDocIdResponse]}")
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio BSS FindCustomerByDocId ${exchangeProperty[findCustomerByDocIdResponse]}")
.when(simple("${exchangeProperty[customerType]} == 'JURIDICO'"))
.process(new FindOrganizationCustomerByDocIdProcessorReq())
.to(configureSsl.setupSSLContext(getCamelContext(), findOrganizacionCustomerByDocId))
.process(new FindOrganizationCustomerByDocIdProcessorRes())
/*.log("\n["+getCurrentDate()+"]"+"Entrada del microservicio FindOrganizationCustomerByDocId ${exchangeProperty[findOrganizationCustomerByDocIdRequest]}") */
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio FindOrganizationCustomerByDocId ${exchangeProperty[findOrganizationCustomerByDocIdResponse]}")
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+"Salida del microservicio BSS FindCustomerByDocId ${exchangeProperty[findCustomerByDocIdResponse]}")
.endChoice()
.endDoTry()
.doCatch(RequiredValueException.class)
.process(new FindCustomerByDocIdProcessorInvalidFormatException())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
.doCatch(HttpHostConnectException.class)
.process(new FindCustomerByDocIdProcessorHttpHostConectionException())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
.doCatch(NotFoundDataException.class)
.process(new FindCustomerByDocIdProcessorInformationSubscriber())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
.doCatch(UnknownHostException.class)
.process(new FindCustomerByDocIdProcessorHttpHostConectionException())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
.doCatch(NoHttpResponseException.class)
.process(new FindCustomerByDocIdProcessorHttpHostConectionException())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION)
.doCatch(Exception.class)
.process(new FindCustomerByDocIdProcessorException())
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+MSG_EXCEPTION)
.log("\n[${bean:BeanDate.getCurrentDateTime()}] "+SALIDA_BSS_EXCEPTION);
}
}
Варианты конфигурации:
camel.component.caffeine-cache.expire-after-write-time
camel.component.caffeine-cache.expire-after-access-time
Применяется только в том случае, если для параметра evictionType
установлено значение TIME_BASED
. По умолчанию — SIZE_BASED
. Таким образом, write-time
и access-time
не будут иметь никакого эффекта.
Вы можете настроить тип выселения следующим образом:
camel.component.caffeine-cache.eviction-type = TIME_BASED
См. документацию по компоненту Camel Caffeine: