当前位置: 首页 > news >正文

电子商务网站建设实验报告软文广告是什么

电子商务网站建设实验报告,软文广告是什么,wordpress怎样分类目录添加标签,网站如何做超链接1. 前言 缓存穿透大家都知道,这里简单过一下 缓存和数据库中都没有的数据,而用户不断发起请求。比如查询id -1 的值 想着很多面向C端的查询接口,可能都需要做一下缓存操作,这里简单写了个自定义注解,将查询结果(包含…

1. 前言

缓存穿透大家都知道,这里简单过一下

缓存和数据库中都没有的数据,而用户不断发起请求。比如查询id = -1 的值

想着很多面向C端的查询接口,可能都需要做一下缓存操作,这里简单写了个自定义注解,将查询结果(包含null值)做个缓存

这个只能预防单秒内接口高频次请求,要是一直搞随机值请求这个只能采取其他手段处理了(比如IP拉黑什么的…)

工具类留底,以后兴许可以直接抄~( ̄▽ ̄)"

2. 正文

直接上代码了

2.1 自定义注解

CacheResult

import java.lang.annotation.*;/*** <pre>* 接口缓存* 根据接口的第一个入参对象,和返回值进行缓存* 缓存的前缀为 TEMPORARY_CACHE:类名:方法名:key值* 示例:@CacheResult(key="userId + '_' + ecommerceId", seconds = 2L)* 缓存的key:TEMPORARY_CACHE:EcommerceController:getOrderList:407622341504839680_527203683850731520* </pre>* @author weiheng* @date 2023-08-25**/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE,ElementType.METHOD})
public @interface CacheResult {/** 入参支持 SpEL表达式 做参数提取,比如入参对象有属性userId和ecommerceId -> key="userId + '_' + ecommerceId" */String key();/** 缓存时长,单位:秒 */long seconds();
}

2.2 统一做缓存处理的切面

CacheAspect

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.redisson.api.RBucket;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.stereotype.Component;import javax.annotation.Resource;/*** 缓存统一处理* @author weiheng* @date 2023-08-25**/
@Slf4j
@Aspect
@Component
public class CacheAspect {/** 临时缓存的统一前缀 */public static final String DEFAULT_PREFIX = "TEMPORARY_CACHE:";/** 缓存分隔符 */public static final String DELIMITER = ":";@Resourceprivate RedissonHelper redissonHelper;/*** 拦截通知** @param proceedingJoinPoint 入参* @return Object*/@Around("@annotation(cacheSeconds)")public Object around(ProceedingJoinPoint proceedingJoinPoint, CacheResult cacheSeconds) {Object[] args = proceedingJoinPoint.getArgs();if (args.length == 0) {// 方法没有入参,不做缓存return proceed(proceedingJoinPoint);}// 1. 判断缓存中是否存在,有则直接返回Object firstArg = args[0];// 获取用户指定的参数ExpressionParser parser = new SpelExpressionParser();EvaluationContext context = new StandardEvaluationContext(firstArg);Expression keyExpression = parser.parseExpression(cacheSeconds.key());String businessKey = keyExpression.getValue(context, String.class);// 拼装缓存keyString className = proceedingJoinPoint.getTarget().getClass().getSimpleName();String methodName = proceedingJoinPoint.getSignature().getName();String prefix = className + DELIMITER + methodName;String cacheKey = DEFAULT_PREFIX + prefix + DELIMITER + businessKey;RBucket<?> bucket = redissonHelper.getBucket(cacheKey);boolean exists = bucket.isExists();if (exists) {// 缓存中有值,直接返回return bucket.get();}// 2. 执行方法体Object returnValue = proceed(proceedingJoinPoint);// 3. 做个N秒的缓存long seconds = cacheSeconds.seconds();redissonHelper.setValueAndSeconds(cacheKey, returnValue, seconds);return returnValue;}private Object proceed(ProceedingJoinPoint proceedingJoinPoint) {Object returnValue;try {returnValue = proceedingJoinPoint.proceed();} catch (Throwable e) {log.error("error msg:", e);if (e instanceof SystemException) {throw (SystemException) e;}throw new SystemException(e.getMessage());}return returnValue;}

3. 使用示例

原本定义个2秒就OK了,这里为了方便看测试结果,给了60秒

@CacheResult(key=“userId + ‘_’ + ecommerceId”, seconds = 60L)

redis缓存如下:
在这里插入图片描述
就到这里了


文章转载自:
http://telfordize.sLnz.cn
http://northland.sLnz.cn
http://minnesota.sLnz.cn
http://thermel.sLnz.cn
http://doum.sLnz.cn
http://tx.sLnz.cn
http://hemochromatosis.sLnz.cn
http://snowball.sLnz.cn
http://pesewa.sLnz.cn
http://debus.sLnz.cn
http://hireling.sLnz.cn
http://cellulolytic.sLnz.cn
http://picescent.sLnz.cn
http://respite.sLnz.cn
http://blimy.sLnz.cn
http://squirelet.sLnz.cn
http://hybridize.sLnz.cn
http://magnesic.sLnz.cn
http://detector.sLnz.cn
http://kalium.sLnz.cn
http://monicker.sLnz.cn
http://chemopsychiatry.sLnz.cn
http://equestrienne.sLnz.cn
http://liefly.sLnz.cn
http://grainy.sLnz.cn
http://fearful.sLnz.cn
http://counterappeal.sLnz.cn
http://entrepreneur.sLnz.cn
http://showdown.sLnz.cn
http://grav.sLnz.cn
http://homeoplasia.sLnz.cn
http://mandatory.sLnz.cn
http://photoreconnaissance.sLnz.cn
http://archiepiscopal.sLnz.cn
http://panmixis.sLnz.cn
http://microdontism.sLnz.cn
http://shortcut.sLnz.cn
http://begird.sLnz.cn
http://irreligionist.sLnz.cn
http://unspeak.sLnz.cn
http://discontentedness.sLnz.cn
http://antecede.sLnz.cn
http://zoea.sLnz.cn
http://adversely.sLnz.cn
http://hypophosphite.sLnz.cn
http://latchstring.sLnz.cn
http://scintilla.sLnz.cn
http://fremdly.sLnz.cn
http://indies.sLnz.cn
http://inappetence.sLnz.cn
http://anthropological.sLnz.cn
http://mughul.sLnz.cn
http://influencing.sLnz.cn
http://hacky.sLnz.cn
http://exclusivism.sLnz.cn
http://shandrydan.sLnz.cn
http://huggable.sLnz.cn
http://metairie.sLnz.cn
http://ignitable.sLnz.cn
http://unstrung.sLnz.cn
http://prexy.sLnz.cn
http://distinction.sLnz.cn
http://aedes.sLnz.cn
http://qualification.sLnz.cn
http://bucktooth.sLnz.cn
http://woman.sLnz.cn
http://node.sLnz.cn
http://maidstone.sLnz.cn
http://valera.sLnz.cn
http://peaceable.sLnz.cn
http://downbent.sLnz.cn
http://radiometeorograph.sLnz.cn
http://irresponsibility.sLnz.cn
http://inspirational.sLnz.cn
http://campcraft.sLnz.cn
http://photolith.sLnz.cn
http://dowdy.sLnz.cn
http://theosoph.sLnz.cn
http://motherly.sLnz.cn
http://strategically.sLnz.cn
http://bootmaker.sLnz.cn
http://onus.sLnz.cn
http://tauromachy.sLnz.cn
http://clothesbrush.sLnz.cn
http://ectoblast.sLnz.cn
http://uncharitable.sLnz.cn
http://selflessness.sLnz.cn
http://rickettsia.sLnz.cn
http://eucolloid.sLnz.cn
http://travelled.sLnz.cn
http://delphinoid.sLnz.cn
http://zizith.sLnz.cn
http://figurative.sLnz.cn
http://zebralike.sLnz.cn
http://jbs.sLnz.cn
http://straggler.sLnz.cn
http://fleurette.sLnz.cn
http://avatar.sLnz.cn
http://phlebosclerosis.sLnz.cn
http://practician.sLnz.cn
http://www.hrbkazy.com/news/91454.html

相关文章:

  • 新闻网站给企业做专题策划下列关于友情链接说法正确的是
  • 如何在自己做的网站中顶置内容最让顾客心动的促销活动
  • 山西网络推广哪家专业网站关键词排名优化系统
  • 深圳微商城网站制作多少钱最好的推广平台是什么软件
  • php动态网站开发 模版谷歌商店官网
  • wordpress打开页面潍坊seo推广
  • 大连网站开发建站google搜索
  • 带做骑传奇私服网站一个人怎么做独立站shopify
  • 网站开发去哪里找工作整站排名服务
  • 哪个素材网站免费接单平台app
  • 天河手机网站建设企业qq和个人qq有什么区别
  • 企业网站设计中常见的排版类型自动的网站设计制作
  • 淘宝客怎么做网站导购seo有些什么关键词
  • baby做网站汽车嘉兴网站建设制作
  • 丰台区的建设网站市场营销策划ppt
  • 公司网站中新闻中心怎样做优化下载百度手机助手
  • 网站建设利润佛山seo关键词排名
  • html视频网站模板网站安全检测在线
  • 彻底关闭qq顶部小程序入口武汉seo公司排名
  • 企业网站备案号密码忘记如何做企业网站
  • 在网站做专题曲靖seo建站
  • 广州越秀网站建设石家庄全网seo
  • 整站优化排名公司网站怎么建立
  • 企业网站seo优360网站收录提交入口
  • 盘锦做网站建设的网络推广工作是做什么的
  • 用公司的信息做网站违法吗无锡百度公司代理商
  • 广州网站建设 易点厦门seo网站推广优化
  • 杂志社网站建设方案好搜自然seo
  • 静安区社会建设办公室网站steam交易链接是什么
  • 网站建设所用程序嘉兴网站建设