口碑好的网站开发公司电话,小工厂如何找外贸公司合作,网站开发设计方案,iis怎么使用来建设一个网站Spring Cache是一个框架#xff0c;实现了基于注解的缓存功能#xff0c;只需要简单地加一个注解#xff0c;就能实现缓存功能。
Spring Cache提供了一层抽象#xff0c;底层可以切换不同的缓存实现#xff0c;例如#xff1a;
①EHCache
②Caffeine
③Redis 常用注解…Spring Cache是一个框架实现了基于注解的缓存功能只需要简单地加一个注解就能实现缓存功能。
Spring Cache提供了一层抽象底层可以切换不同的缓存实现例如
①EHCache
②Caffeine
③Redis 常用注解 代码开发
package com.itheima.controller;import com.itheima.entity.User;
import com.itheima.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;RestController
RequestMapping(/user)
Slf4j
public class UserController {Autowiredprivate UserMapper userMapper;PostMappingCachePut(cacheNames userCache,key#user.id)//如果使用Spring Cache缓存数据key的生成userCache::1public User save(RequestBody User user){userMapper.insert(user);return user;}DeleteMappingCacheEvict(cacheNames userCache,key #id)public void deleteById(Long id){userMapper.deleteById(id);}DeleteMapping(/delAll)CacheEvict(cacheNames userCache,allEntries true)public void deleteAll(){userMapper.deleteAll();}GetMappingCacheable(cacheNames userCache,key #id)//key的生成userCache::10public User getById(Long id){User user userMapper.getById(id);return user;}}