Springboot-redis Cache

Source: Internet
Author: User
Redis Cache Usage

1. Introduction of dependencies (may have been introduced): Spring-boot-starter-cache

2. Configure the Spring:redis:host/port/password in the Application.yml configuration file to connect to the Redis library

3. Add annotations to the main launcher: @EnableChaching

4. Add annotations to the method that requires caching:@Cacheable (cachename= "". key= "")

5. The outermost object of the return page needs to be serialized: Implement Interface serializable

6. Use the Generateserialversionuid plugin to generate unique IDs for objects that need to be serialized (using shortcut keys)

Redis Cache Update

Method One: Add annotations to the method that needs to update the cache:@CachePut (cachename= "". key= "")

Note: Sometimes the returned data is not in JSON format but in view format, when serialization fails, and this method cannot be used

Method Two: Add a note to the method that needs to delete the cache:@CacheEvict (cachename= "". key= "")

Springboot-redis Cache

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.