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

php做的网站如何该样式快速优化seo软件推广方法

php做的网站如何该样式,快速优化seo软件推广方法,wordpress 采集 入库,公众号用什么软件制作最好目录 1. 热点数据缓存 1.1 什么是缓存? 1.2 缓存的原理 1.3 什么样的数据适合放入缓存中 1.4 哪个组件可以作为缓存 1.5 java使用redis如何实现缓存功能 1.5.1 需要的依赖 1.5.2 配置文件 1.5.3 代码 1.5.4 发现 1.6 使用缓存注解完成缓存功能 2. 分布式锁…

目录

1. 热点数据缓存

1.1 什么是缓存?

1.2 缓存的原理

1.3 什么样的数据适合放入缓存中

1.4 哪个组件可以作为缓存

1.5 java使用redis如何实现缓存功能

1.5.1 需要的依赖

1.5.2  配置文件

 1.5.3 代码

 1.5.4 发现

1.6 使用缓存注解完成缓存功能

2. 分布式锁

2.1模拟高并发

2.2 使用syn和lock锁

2.3 模拟多服务器

 2.4 nginx代理集群

2.5 使用redis解决分布式锁文件


1. 热点数据缓存

1.1 什么是缓存?

 为了把一些经常访问的数据,放入缓存中以减少对数据库的访问频率。从而减少数据库的压力,提高程序的性能。(内存中存储)

1.2 缓存的原理

1.3 什么样的数据适合放入缓存中

  1. 查询频率高且修改频率低
  2.  数据安全性低

1.4 哪个组件可以作为缓存

  1. redis组件
  2. memory组件
  3. ehcache组件

1.5 java使用redis如何实现缓存功能

1.5.1 需要的依赖

 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.3</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency>

1.5.2  配置文件

server.port=8080#数据源
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/1suo?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=12345678#mybatisplus的sql日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#mapper映射文件
mybatis-plus.mapper-locations=classpath*:mapper/*.xml#redis配置
spring.redis.host=172.16.7.192
spring.redis.port=6379
spring.redis.database=1

 1.5.3 代码

控制层

package com.ls.controller;import com.ls.entity.Clazz;
import com.ls.service.ClazzService;
import com.ls.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;/*** @program: springboot-redis-cache* @description:* @author: 1suo* @create: 2024-07-24 19:56**/
@RestController
@RequestMapping("clazz")
public class ClazzController {@Autowiredprivate ClazzService clazzService;@DeleteMapping("delete")public R delete(Integer id) {return clazzService.delete(id);}@GetMapping("get")public R get(Integer id) {return clazzService.get(id);}@GetMapping("getAll")public R getAll() {return clazzService.getAll();}@PostMapping("save")public R save(@RequestBody Clazz clazz) {return clazzService.save(clazz);}@PutMapping("update")public R update(Clazz clazz) {return clazzService.update(clazz);}
}

业务层

package com.ls.service.impl;import com.ls.dao.ClazzDao;
import com.ls.entity.Clazz;
import com.ls.service.ClazzService;
import com.ls.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import sun.dc.pr.PRError;import java.util.ArrayList;
import java.util.List;/*** @program: springboot-redis-cache* @description:* @author: 1suo* @create: 2024-07-24 19:57**/
@Service
public class ClazzServiceImpl implements ClazzService {@Autowiredprivate ClazzDao clazzDao;@Autowiredprivate RedisTemplate<String, Object> redisTemplate;@Overridepublic R save(Clazz clazz) {int insert = clazzDao.insert(clazz);return new R(200,"保存成功",clazz);}@Overridepublic R update(Clazz clazz) {int update = clazzDao.updateById(clazz);if (update>0){redisTemplate.opsForValue().set("clazz::" + clazz.getCid(),clazz);}return new R(200,"更新成功",clazz);}@Overridepublic R delete(Integer id) {int delete = clazzDao.deleteById(id);if (delete>0){redisTemplate.delete("clazz::" + id);}return new R(200,"删除成功",id);}@Overridepublic R get(Integer id) {ValueOperations<String, Object> forValue = redisTemplate.opsForValue();Object o = forValue.get("clazz::" + id);if(o!=null){return new R(200,"查询成功",(Clazz)o);}Clazz clazz = clazzDao.selectById(id);if (clazz!=null){forValue.set("clazz::" + id,clazz);}return new R(500,"查询成功",clazz);}@Overridepublic R getAll() {List<Clazz> list = clazzDao.selectList(null);return new R(200,"查询成功",list);}
}

dao层

package com.ls.dao;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ls.entity.Clazz;/*** @program: springboot-redis-cache* @description:* @author: 1suo* @create: 2024-07-25 08:41**/
public interface ClazzDao extends BaseMapper<Clazz> {
}

实体类

package com.ls.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;/*** @program: springboot-redis-cache* @description:* @author: 1suo* @create: 2024-07-24 19:56**/
@Data
@NoArgsConstructor
@AllArgsConstructor@TableName("tbl_clazz")
public class Clazz {@TableId(type = IdType.AUTO)private Integer cid;private String cname;
}

 配置类

package com.ls.config;import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;@Configuration
public class RedisConfig {@Beanpublic RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory factory){RedisTemplate<String, Object> template = new RedisTemplate<>();//创建redisTemplate对象StringRedisSerializer serializer = new StringRedisSerializer();//字符串序列化对象Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);//Jackson的序列化对象ObjectMapper om = new ObjectMapper();om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);jackson2JsonRedisSerializer.setObjectMapper(om);template.setConnectionFactory(factory);
//        key序列化方式template.setKeySerializer(serializer);
//        value序列化template.setValueSerializer(jackson2JsonRedisSerializer);
//        value hashmap序列化template.setHashValueSerializer(jackson2JsonRedisSerializer);template.setKeySerializer(serializer);return template;}
}

@MapperScan("com.ls.dao") 注解,将dao层自动代理为Mapper代理对象。

 1.5.4 发现

业务层代码除了要维护核心业务功能外,额外还要维护缓存的代码。

解决: 使用AOP面向切面编程。(spring框架用aop切面实现)

1.6 使用缓存注解完成缓存功能

必须spring缓存使用的组件。 

config:为解决序列化的问题

 @Beanpublic CacheManager cacheManager(RedisConnectionFactory factory) {RedisSerializer<String> redisSerializer = new StringRedisSerializer();Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);//解决查询缓存转换异常的问题ObjectMapper om = new ObjectMapper();om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);jackson2JsonRedisSerializer.setObjectMapper(om);// 配置序列化(解决乱码的问题),过期时间600秒RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(600)) //缓存过期10分钟 ---- 业务需求。.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))//设置key的序列化方式.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)) //设置value的序列化.disableCachingNullValues();RedisCacheManager cacheManager = RedisCacheManager.builder(factory).cacheDefaults(config).build();return cacheManager;}

 开启缓存注解

 

 使用

package com.ls.service.impl;import com.ls.dao.ClazzDao;
import com.ls.entity.Clazz;
import com.ls.service.ClazzService;
import com.ls.vo.R;
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.cache.annotation.EnableCaching;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import sun.dc.pr.PRError;import java.util.ArrayList;
import java.util.List;/*** @program: springboot-redis-cache* @description:* @author: 1suo* @create: 2024-07-24 19:57**/
@Service
public class ClazzServiceImpl implements ClazzService {@Autowiredprivate ClazzDao clazzDao;@Autowiredprivate RedisTemplate<String, Object> redisTemplate;@Overridepublic R save(Clazz clazz) {int insert = clazzDao.insert(clazz);return new R(200,"保存成功",clazz);}@CachePut(cacheNames = "clazz", key = "#clazz.cid")@Overridepublic Clazz update(Clazz clazz) {int update = clazzDao.updateById(clazz);return clazz;}@CacheEvict(cacheNames = "clazz", key = "#id")@Overridepublic R delete(Integer id) {int delete = clazzDao.deleteById(id);return new R(200,"删除成功",id);}@Cacheable(cacheNames = "clazz", key = "#id")@Overridepublic Clazz get(Integer id) {Clazz clazz = clazzDao.selectById(id);return clazz;}@Overridepublic R getAll() {List<Clazz> list = clazzDao.selectList(null);return new R(200,"查询成功",list);}
}

2. 分布式锁

2.1模拟高并发

使用jmeter压测工具:

第一步:

 第二步:

 第三步:

 通过压测发现库存超卖和重卖了,解决办法使用锁

2.2 使用syn和lock锁

public String decrement(Integer productid) {//根据id查询商品的库存int num = stockDao.findById(productid);synchronized (this) {if (num > 0) {//修改库存stockDao.update(productid);System.out.println("商品编号为:" + productid + "的商品库存剩余:" + (num - 1) + "个");return "商品编号为:" + productid + "的商品库存剩余:" + (num - 1) + "个";} else {System.out.println("商品编号为:" + productid + "的商品库存不足。");return "商品编号为:" + productid + "的商品库存不足。";}}}

 上面使用syn和lock虽然解决了并发问题,但是我们未来项目部署时可能要部署集群模式

2.3 模拟多服务器

点击增加一个服务器,同时启动后,实现模拟多服务器。 下面是服务器配置。

 启动俩个服务器:

 2.4 nginx代理集群

下载window版本的nginx实现代理集群。

nginx.conf配置文件:

 通过压测发现本地锁 无效了,使用redis解决分布式锁文件

2.5 使用redis解决分布式锁文件

 核心代码:

@Service
public class StockService {@Autowiredprivate StockDao stockDao;@Autowiredprivate RedissonClient redisson;//public String decrement(Integer productid) {RLock lock = redisson.getLock("product::" + productid);lock.lock();try {//根据id查询商品的库存: 提前预热到redis缓存中int num = stockDao.findById(productid);if (num > 0) {//修改库存---incr---定时器[redis  数据库同步]stockDao.update(productid);System.out.println("商品编号为:" + productid + "的商品库存剩余:" + (num - 1) + "个");return "商品编号为:" + productid + "的商品库存剩余:" + (num - 1) + "个";} else {System.out.println("商品编号为:" + productid + "的商品库存不足。");return "商品编号为:" + productid + "的商品库存不足。";}}finally {lock.unlock();}}
}


文章转载自:
http://dinncoobmutescence.stkw.cn
http://dinncolitterateur.stkw.cn
http://dinncosubmarine.stkw.cn
http://dinncounmanliness.stkw.cn
http://dinncobordello.stkw.cn
http://dinncomarlite.stkw.cn
http://dinncoequidistant.stkw.cn
http://dinncohereinbefore.stkw.cn
http://dinncopolyzonal.stkw.cn
http://dinncoembarrassedly.stkw.cn
http://dinncoaerification.stkw.cn
http://dinncohydrocephalic.stkw.cn
http://dinncocatholicate.stkw.cn
http://dinncocellophane.stkw.cn
http://dinncosobriety.stkw.cn
http://dinncoles.stkw.cn
http://dinncohaematoid.stkw.cn
http://dinncoeuclase.stkw.cn
http://dinncoconga.stkw.cn
http://dinncovermicule.stkw.cn
http://dinncoopacus.stkw.cn
http://dinncovon.stkw.cn
http://dinnconundine.stkw.cn
http://dinncocoimbatore.stkw.cn
http://dinncotransmissible.stkw.cn
http://dinncoaureus.stkw.cn
http://dinncoseasonably.stkw.cn
http://dinncowelsh.stkw.cn
http://dinncodreamful.stkw.cn
http://dinncomonoploid.stkw.cn
http://dinncopotentate.stkw.cn
http://dinncoketonuria.stkw.cn
http://dinncomegacorpse.stkw.cn
http://dinncoextracellular.stkw.cn
http://dinncoabmigration.stkw.cn
http://dinncowired.stkw.cn
http://dinncohospitality.stkw.cn
http://dinncotiresias.stkw.cn
http://dinncotriturable.stkw.cn
http://dinncopopulism.stkw.cn
http://dinncostrigous.stkw.cn
http://dinncosynthetic.stkw.cn
http://dinncolivestock.stkw.cn
http://dinncominiature.stkw.cn
http://dinncoschizophreniform.stkw.cn
http://dinncomonoploid.stkw.cn
http://dinncozymologist.stkw.cn
http://dinncomultiplicand.stkw.cn
http://dinncophotology.stkw.cn
http://dinncolotion.stkw.cn
http://dinncorommany.stkw.cn
http://dinncosubordinating.stkw.cn
http://dinncometatrophic.stkw.cn
http://dinncotheatergoer.stkw.cn
http://dinncomesopotamia.stkw.cn
http://dinncoslaister.stkw.cn
http://dinncomarkovian.stkw.cn
http://dinncowobbegong.stkw.cn
http://dinncoepistolary.stkw.cn
http://dinncoaccordant.stkw.cn
http://dinncoovertook.stkw.cn
http://dinncoriven.stkw.cn
http://dinncozoophysiology.stkw.cn
http://dinncobroche.stkw.cn
http://dinncoimpartially.stkw.cn
http://dinncocreepy.stkw.cn
http://dinncospendthriftiness.stkw.cn
http://dinncoexegetics.stkw.cn
http://dinncoimmoderation.stkw.cn
http://dinncoredemptive.stkw.cn
http://dinncofalloff.stkw.cn
http://dinncohalavah.stkw.cn
http://dinncorochelle.stkw.cn
http://dinncohydriodic.stkw.cn
http://dinncocellarage.stkw.cn
http://dinncocipher.stkw.cn
http://dinncoinbeing.stkw.cn
http://dinncoscroop.stkw.cn
http://dinncotawdry.stkw.cn
http://dinncofool.stkw.cn
http://dinncosquarehead.stkw.cn
http://dinncofluosilicate.stkw.cn
http://dinncotransjordan.stkw.cn
http://dinncobarbicel.stkw.cn
http://dinncocoruscate.stkw.cn
http://dinncovitrescence.stkw.cn
http://dinncoironside.stkw.cn
http://dinncoalkalosis.stkw.cn
http://dinncowobble.stkw.cn
http://dinncopinocytic.stkw.cn
http://dinnconongreen.stkw.cn
http://dinncochannel.stkw.cn
http://dinncoemasculate.stkw.cn
http://dinncoalum.stkw.cn
http://dinncokermes.stkw.cn
http://dinncofluosilicate.stkw.cn
http://dinncocornaceae.stkw.cn
http://dinncoravishment.stkw.cn
http://dinncoinjection.stkw.cn
http://dinncorudd.stkw.cn
http://www.dinnco.com/news/140887.html

相关文章:

  • 德州有做网站的端口扫描站长工具
  • 网站建设 上海交大装修公司网络推广方案
  • 企业做网站需要的资料今日冯站长之家
  • 怎么建设一个网站赚钱新开发的app怎么推广
  • 黄页 网站模板关键词优化教程
  • 长沙网站建设工作室可以免费发广告的网站
  • 那些卖外挂的怎么做的网站seo短期培训班
  • 一 电子商务网站建设规划网站模板库官网
  • 零件加工网上接订单seo批量建站
  • 做网站每年需付费吗微博指数查询
  • 哪个公司网站设计好外贸网站推广优化
  • 怎么靠做网站赚钱吗目前搜索引擎排名
  • 诚信建设万里行网站网盘网页版
  • 购物网站seo互动营销经典案例
  • 官方网站欣赏广州百度竞价外包
  • 做正常站网站都被墙了seo创业
  • 猪八戒做网站靠谱吗长沙关键词优化服务
  • 做电子政务网站四川seo技术培训
  • 网页设计的步骤有哪些广州seo推广
  • 深圳做网站开发费用seo自动刷外链工具
  • 网站被降权会发生什么推广方案经典范文
  • 建设一个网站是不必须备案搜索引擎优化简历
  • 可以做卷子的网站网络推广有效果吗
  • 做资源下载网站条件新东方教育机构官网
  • 深圳自适应网站建设价格惠州seo排名收费
  • 网页设计图片代码怎么写seo是什么意思为什么要做seo
  • 网站内容标签设计怎么在百度制作自己的网站
  • 网站和微信公众号建设方案chrome浏览器官网入口
  • 网站建设方案视频教程西安seo优化培训
  • sae 企业网站开源crm系统