'Spring caching behaviour in case of an error
I have Spring Boot and cacheable method:
@Cacheable("ids")
public List<String> getValidIds() {
return list_from_another_service;
}
I have the cache eviction config:
@Scheduled(fixedRateString = "PT60M")
@CacheEvict(value = "ids", allEntries = true)
public void evictCache() {
//Do nothing.
}
Question:
The cache is evicted each 1 hr. What should the cache return if getValidIds() method receives an error during cache refreshing?
Will the cache be empty for 1 hour or will it still store and return the data from the previous successful call?
Solution 1:[1]
Using the Link will append the address link to your homepage.
See more of Link from React Router: https://v5.reactrouter.com/web/api/Link
You can do this to open the address in different tab.
<button
className="button"
onClick={() => {
window.open(btnLink);
}}
>
{btnText}
</button>
or if you want to open the address in the same tab.
<button
className="button"
onClick={() => {
window.location.href = btnLink
}}
>
{btnText}
</button>
Solution 2:[2]
Using the Link component from react-router-dom will not work with external links that go away from your site URL. Something such as https://www.google.com will not work with that component. Instead, you will need to have an <a /> tag here and utilize the href attribute. You can simply style the <a /> tag link a button to get the behavior you are looking for once it is clicked. Here is a code example using a custom styled-component:
import React from 'react';
import styled from 'styled-components';
const LinkButtonComponent = styled.a`
text-decoration: none !important;
color: white;
background-color: green;
padding: 2px;
border-radius: 3px;
height: 50px;
width: 100px;
cursor: pointer;
`;
type LinkButtonProps = {
children: React.ReactNode;
};
export default function LinkButton({ children }: LinkButtonProps) {
return (
<LinkButtonComponent href='https://www.google.com'>
{children}
</LinkButtonComponent>
);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shan |
| Solution 2 | Simeon Ikudabo |
