分布式多级缓存(本地缓存,redis缓存)

结构包:

 使用案例:

 实现效果:

1、基本并发的本地缓存,基于分布式轻量级锁的redis缓存

2、热缓存(高频访问持续缓存)+快速过期(本地缓存2秒,redis缓存10秒)

3、方法级别缓存清理 (@HybridCache 与@HybridChange 绑定管理缓存 )

4、基于HybridType接口的可扩展式作用域,目前已实现:全局、token

5、基于HybridLevel接口的可扩展式缓存处理,目前已实现:本地缓存、redis缓存

核心代码包:

 @HybridCache

package com.*.server.live.core.hybridCache;

import com.*.server.live.core.hybridCache.impl.DepthLocal;
import com.*.server.live.core.hybridCache.impl.DepthRedis;

import java.lang.annotation.*;

/**
 * 功能描述:多重缓存
 * 作者:唐泽齐
 * @case @HybridCache(scope = ScopeGlobal.class)
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface HybridCache {

    /*缓存深度*/
    Class<? extends HybridLevel> depth() default DepthRedis.class;

    /*缓存广度*/
    Class<? extends HybridType> scope();

}

@HybridCache

 @HybridChange

package com.*.server.live.core.hybridCache;

import com.*.server.live.core.hybridCache.impl.DepthRedis;

import java.lang.annotation.*;

/**
 * 功能描述:多重缓存更新
 * 作者:唐泽齐
 * @case @HybridChange(clazz = LiveStudioController.class,method = "getStudio",args = {Long.class})
 * @case @HybridChange(clazz = LiveStudioController.class,method = "getStudio",args = {})
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface HybridChange {

    /*关联类*/
    Class<? extends Object> clazz();

    /*关联方法*/
    String method();

    /*关联方法入参类型*/
    Class<?>[] args();
}

@HybridChange

 HybridLevel

package com.*.server.live.core.hybridCache;

import org.aspectj.lang.ProceedingJoinPoint;

import javax.validation.constraints.NotNull;

/**
 * 功能描述:多重缓存级别
 * 作者:唐泽齐
 */
public interface HybridLevel {
    /**
     * 缓存
     * @param key 缓存key
     * @param id 混村ID
     * @param o 缓存值
     * @param self 是否执行节点
     * @param joinPoint 节点
     * @return
     * @throws Throwable
     */
    Object cache(@NotNull String key,@NotNull String id, Object o,@NotNull boolean self,@NotNull ProceedingJoinPoint joinPoint) throws Throwable;

    /**
     * 清缓存
     * @param key 缓存key
     * @param self 是否执行节点
     * @param joinPoint 节点
     * @return
     * @throws Throwable
     */
    Object del(@NotNull String key,@NotNull boolean self,@NotNull ProceedingJoinPoint joinPoint) throws Throwable;
}

HybridLevel

 HybridType


                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值