美文网首页
springboot集成阿里开源多级缓存JetCache

springboot集成阿里开源多级缓存JetCache

作者: 丶君为红颜酔 | 来源:发表于2018-12-13 11:03 被阅读0次

    JetCache

    https://blog.csdn.net/sinat_32366329/article/details/80260944

    依赖

    <dependency>
        <groupId>com.alicp.jetcache</groupId>
        <artifactId>jetcache-starter-redis-lettuce</artifactId>
        <version>2.5.9</version>
    </dependency>
    
    

    配置

    @Configuration
    @EnableMethodCache(basePackages = "input your package name!!!")
    @EnableCreateCacheAnnotation
    public class CacheConfig {
    
    }
    
    
    jetcache:
      statIntervalMinutes: 15
      areaInCacheName: false
      hiddenPackages: com.alibaba
      local:
        default:
          type: caffeine
          limit: 100
          keyConvertor: fastjson
          expireAfterWriteInMillis: 100000
      remote:
        default:
          type: redis.lettuce
          keyConvertor: fastjson
          valueEncoder: kryo
          valueDecoder: kryo
          uri: redis://XXX@host:6379/6
    

    使用

    public interface UserService {
        @Cached(name="userCache.", key="#userId", expire = 3600 ,cacheType = CacheType.BOTH)
        User getUserById(long userId);
     
        @CacheUpdate(name="userCache.", key="#user.userId", value="#user")
        void updateUser(User user);
     
        @CacheInvalidate(name="userCache.", key="#userId")
        void deleteUser(long userId);
    }
    
    

    相关文章

      网友评论

          本文标题:springboot集成阿里开源多级缓存JetCache

          本文链接:https://www.haomeiwen.com/subject/wmevhqtx.html