spring缓存的使用

Spring缓存使用

缓存注解

对于Spring,缓存组件例如EhCache是可拔插的,而缓存注解是通用的。

@Cacheable

标记在方法或者类上,标识该方法或类支持缓存。Spring调用注解标识方法后会将返回值缓存到redis,以保证下次同条件调用该方法时直接从缓存中获取返回值。这样就不需要再重新执行该方法的业务处理过程,提高效率。
@Cacheable常用的三个参数如下:
cacheNames 缓存名称
key 缓存的key,需要注意key的写法哈
condition 缓存执行的条件,返回true时候执行
cacheManager 使用的cacheManager的bean名称
sync 如果多个请求同时来访问同一个key的数据,则sync表示加锁同步,等第一个请求返回数据后,其他请求直接获取缓存里的数据。

@Cacheable(value = "DICT", key = "'getDictById'+#id", sync = true)
@CachePut

标记在方法或者类上,标识该方法或类支持缓存。每次都会执行目标方法,并将执行结果以键值对的形式存入指定的缓存中。

@CachePut(value = "DICT", key = "'getDictById'+#model.getId()")
@CacheEvict

@CacheEvict是用来标注在需要清除缓存元素的方法或类上的。@CacheEvict可以指定的属性有value、key、condition、allEntries和beforeInvocation。其中value、key和condition的语义与@Cacheable对应的属性类似。即
value表示清除操作是发生在哪些Cache上的(对应Cache的名称);
key表示需要清除的是哪个key,如未指定则会使用默认策略生成的key;
condition表示清除操作发生的条件。
allEntries是boolean类型,表示是否需要清除缓存中的所有元素。默认为false,表示不需要。当指定了allEntries为true时,Spring Cache将忽略指定的key。
beforeInvocation 清除操作默认是在对应方法成功执行之后触发的,即方法如果因为抛出异常而未能成功返回时也不会触发清除操作。当我们指定该属性值为true时,Spring会在调用该方法之前清除缓存中的指定元素。

@CacheEvict(value = "DICT",key = "'getDictById'+#model.getId()",beforeInvocation=false)

使用Ehcache作为缓存

pom坐标
  <dependency><groupId>net.sf.ehcache</groupId><artifactId>ehcache</artifactId><version>2.8.3</version></dependency><!-- Ehcache依赖此组件创建bean --><dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><version>5.1.5.RELEASE</version></dependency>
ehcache.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"updateCheck="false"><diskStore path="java.io.tmpdir/Tmp_EhCache" /><!-- defaultCache,是默认的缓存策略 --><!-- 如果你指定的缓存策略没有找到,那么就用这个默认的缓存策略 --><!-- external:缓存对象是否一直存在,如果设置为true的话,那么timeout就没有效果,缓存就会一直存在,一般默认就是false --><!-- maxElementsInMemory:内存中可以缓存多少个缓存条目 --><!-- overflowToDisk:如果内存不够的时候,是否溢出到磁盘 --><!-- diskPersistent:是否启用磁盘持久化的机制,在jvm崩溃的时候和重启之间 --><!-- timeToIdleSeconds:对象最大的闲置的时间,如果超出闲置的时间,可能就会过期  单位:秒 当eternal=false对象不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大--><!-- timeToLiveSeconds:对象最多存活的时间  单位:秒 当eternal=false对象不是永久有效时使用,可选属性,默认值是0,也就是存活时间无穷大--><!-- memoryStoreEvictionPolicy:当缓存数量达到了最大的指定条目数的时候,需要采用一定的算法,从缓存中清除一批数据,LRU,最近最少使用算法,最近一段时间内,最少使用的那些数据,就被干掉了 --><defaultCacheeternal="false"maxElementsInMemory="1000"overflowToDisk="false"diskPersistent="false"timeToIdleSeconds="300"timeToLiveSeconds="600"memoryStoreEvictionPolicy="LRU" /><!-- 手动指定的缓存策略 --><!-- 对不同的数据,缓存策略可以在这里配置多种 --><cachename="local"  eternal="false"maxElementsInMemory="1000"overflowToDisk="false"diskPersistent="false"timeToIdleSeconds="300"timeToLiveSeconds="600"memoryStoreEvictionPolicy="LRU" />    
</ehcache>
EhcacheConfiguration.java
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;@Configuration
@EnableCaching
public class EhcacheConfiguration {@Beanpublic EhCacheManagerFactoryBean cacheManagerFactoryBean(){EhCacheManagerFactoryBean bean = new EhCacheManagerFactoryBean();bean.setConfigLocation(new ClassPathResource("ehcache.xml"));bean.setShared(true);return bean;}@Beanpublic EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean bean){return new EhCacheCacheManager(bean.getObject());} 
}
使用
@Service
public class EhcahceServiceImpl implements EhcahceService {private static final String CACHE_STRATEGY = "local";@CachePut(value=CACHE_STRATEGY,key="#root.methodName+#info.getProduct_id()")@Overridepublic ProductInfo saveProductInfo(ProductInfo info) throws Exception {return info;}@Cacheable(value=CACHE_STRATEGY,key="#root.methodName+#id")@Overridepublic ProductInfo getProductInfoById(Long id) throws Exception {return null;}}

使用redis作为缓存

pom坐标
        <!--redis 配置--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><exclusions><exclusion><groupId>io.lettuce</groupId><artifactId>lettuce-core</artifactId></exclusion></exclusions></dependency><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId></dependency>
yml配置
spring:# redis配置redis:password: 123456# 集群模式cluster:nodes: 127.0.0.1:1000,127.0.0.1:2000# 哨兵模式#sentinel:#master: sentinel #哨兵的名字 #下面是所有哨兵集群节点#nodes: 11.11.11.111:26379,11.11.11.111:26380jedis:pool:#最大连接数max-active: 200#最大阻塞等待时间(负数表示没限制)max-wait: -1#最大空闲max-idle: 8#最小空闲min-idle: 0#连接超时时间expireSecond: 604800 #7天
redisCacheManage配置

此处设计了两种不同cacheName的redis缓存

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;import java.time.Duration;
import java.util.HashMap;
import java.util.Map;@Configuration
@EnableCaching
@Slf4j
public class CacheConfig {@Value("${spring.redis.expireSecond}")private Integer expireSecond;@Beanpublic CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {return new RedisCacheManager(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory),this.getRedisCacheConfigurationWithTtl(600), // 默认策略,未配置的 key 会使用这个this.getRedisCacheConfigurationMap() // 指定 key 策略);}private Map<String, RedisCacheConfiguration> getRedisCacheConfigurationMap() {Map<String, RedisCacheConfiguration> redisCacheConfigurationMap = new HashMap<>();redisCacheConfigurationMap.put("Dict", this.getRedisCacheConfigurationWithTtl(600));redisCacheConfigurationMap.put("COL_KEY", this.getRedisCacheConfigurationWithTtl(expireSecond));return redisCacheConfigurationMap;}private RedisCacheConfiguration getRedisCacheConfigurationWithTtl(Integer seconds) {RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())).serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())).entryTtl(Duration.ofSeconds(seconds));return config;}
}
使用同上

同时使用两种缓存

配置
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;import java.time.Duration;@Configuration
@EnableCaching
@Slf4j
public class CacheConfig {@Value("${spring.redis.expireSecond}")private Integer expireSecond;@Beanpublic EhCacheManagerFactoryBean cacheManagerFactoryBean() {EhCacheManagerFactoryBean bean = new EhCacheManagerFactoryBean();bean.setConfigLocation(new ClassPathResource("ehcache.xml"));bean.setShared(true);return bean;}@Bean@Primarypublic EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean bean) {return new EhCacheCacheManager(bean.getObject());}@Beanpublic RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {// 使用缓存的默认配置RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())).serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())).entryTtl(Duration.ofSeconds(expireSecond));RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.builder(redisConnectionFactory).cacheDefaults(config);return builder.build();}
}
指定缓存使用
    @Cacheable(value = CACHE_NAME, key = "#root.methodName+#code",cacheManager = "redisCacheManager")

当redis出现问题时,如何禁用redis,直连数据库

1.yml配置文件忽略掉redis配置 spring.autoconfigure.exclude:org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
2.根据条件加载CacheConfig类,当spring.redis.useRedis=true时加载,否则不加载@ConditionalOnProperty(prefix = "spring.redis", value = "useRedis", havingValue = "true", matchIfMissing = true)
public class CacheConfig{}
Redis工具类

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnection;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;import javax.annotation.Resource;@Service
@ConditionalOnProperty(prefix = "spring.redis", value = "useRedis", havingValue = "true", matchIfMissing = true)
public class RedisService {@Resourceprivate RedisConnectionFactory redisConnectionFactory;//会出现循环依赖---Circular reference//RedisService引用JedisPool--JedisPool在RedisService,只有创建RedisService的实例才可以获取JedisPool的bean//所以需要单独拿出JedisPool的bean/*** 获取单个对象** @param prefix* @param key* @param data* @return*/public <T> T get(KeyPrefix prefix, String key, Class<T> data) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();//生成真正的key  className+":"+prefix;  BasePrefix:id1String realKey = prefix.getPrefix() + key;String sval = jedis.get(realKey);//将String转换为Bean入后传出T t = stringToBean(sval, data);return t;} finally {returnToPool(jedisConnection);}}/*** 移除对象,删除** @param prefix* @param key* @return*/public boolean delete(KeyPrefix prefix, String key) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();String realKey = prefix.getPrefix() + key;long ret = jedis.del(realKey);return ret > 0;//删除成功,返回大于0} finally {returnToPool(jedisConnection);}}/*** 设置单个、多个对象** @param prefix* @param key* @param value* @return*/public <T> boolean set(KeyPrefix prefix, String key, T value) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();String realKey = prefix.getPrefix() + key;String s = beanToString(value);if (s == null || s.length() <= 0) {return false;}int seconds = prefix.getExpireSeconds();if (seconds <= 0) { //永不过期jedis.set(realKey, s);} else {jedis.setex(realKey, seconds, s);}return true;} finally {returnToPool(jedisConnection);}}/*** 减少值** @param prefix* @param key* @return*/public <T> Long decr(KeyPrefix prefix, String key) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();String realKey = prefix.getPrefix() + key;return jedis.decr(realKey);} finally {returnToPool(jedisConnection);}}/*** 增加值** @param prefix* @param key* @return*/public <T> Long incr(KeyPrefix prefix, String key) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();String realKey = prefix.getPrefix() + key;return jedis.incr(realKey);} finally {returnToPool(jedisConnection);}}/*** 获取key的过期时间*/public <T> Long ttl(KeyPrefix prefix, String key) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();String realKey = prefix.getPrefix() + key;return jedis.ttl(realKey);} finally {returnToPool(jedisConnection);}}/*** 设置key的过期时间*/public <T> void setExpire(KeyPrefix prefix, String key, int expire) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();String realKey = prefix.getPrefix() + key;jedis.expire(realKey, expire);} finally {returnToPool(jedisConnection);}}/*** 检查key是否存在** @param prefix* @param key* @return*/public <T> boolean exitsKey(KeyPrefix prefix, String key) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();String realKey = prefix.getPrefix() + key;return jedis.exists(realKey);} finally {returnToPool(jedisConnection);}}/*** 将字符串转换为Bean对象* <p>* parseInt()返回的是基本类型int 而valueOf()返回的是包装类Integer* Integer是可以使用对象方法的  而int类型就不能和Object类型进行互相转换 。* int a=Integer.parseInt(s);* Integer b=Integer.valueOf(s);*/public static <T> T stringToBean(String s, Class<T> clazz) {if (s == null || s.length() == 0 || clazz == null) {return null;}if (clazz == int.class || clazz == Integer.class) {return ((T)Integer.valueOf(s));} else if (clazz == String.class) {return (T)s;} else if (clazz == long.class || clazz == Long.class) {return (T)Long.valueOf(s);} else {JSONObject json = JSON.parseObject(s);return JSON.toJavaObject(json, clazz);}}/*** 将Bean对象转换为字符串类型** @param <T>*/public static <T> String beanToString(T value) {//如果是nullif (value == null) {return null;}//如果不是nullClass<?> clazz = value.getClass();if (clazz == int.class || clazz == Integer.class) {return "" + value;} else if (clazz == String.class) {return "" + value;} else if (clazz == long.class || clazz == Long.class) {return "" + value;} else {return JSON.toJSONString(value);}}private void returnToPool(JedisConnection jedisConnection) {if (jedisConnection != null) {RedisConnectionUtils.releaseConnection(jedisConnection, redisConnectionFactory);}}public <T> boolean set(String key, T value) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();//将T类型转换为String类型String s = beanToString(value);if (s == null) {return false;}jedis.set(key, s);return true;} finally {returnToPool(jedisConnection);}}public <T> T get(String key, Class<T> data) {JedisConnection jedisConnection = (JedisConnection)RedisConnectionUtils.getConnection(redisConnectionFactory, true);Jedis jedis = null;try {jedis = jedisConnection.getNativeConnection();String sval = jedis.get(key);//将String转换为Bean入后传出T t = stringToBean(sval, data);return t;} finally {returnToPool(jedisConnection);}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/701781.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++mciSendString开发软件:音乐播放器2.0

目录 目录 目录 回顾上集代码 开始更改! 1、增加色彩特效 效果 2、增加命令行 初始化界面 获取时长 结构体 设置时长 退出 切换音乐 ......(没用的一堆玩意儿) 完整代码 回顾上集代码 #include <Button.h> #include <heker.h> #include <ARTTEXT.h> …

StopWatch的使用

StopWatch的使用 【一】简介【1】不使用StopWatch的案例【2】使用StopWatch的案例 【二】源码分析【1】查看源码【2】StopWatch优缺点&#xff1a; 【一】简介 stopWatch是org.springframework.util包下的一个工具类&#xff0c;使用它可直观的输出代码执行耗时&#xff0c;以…

MySQL--索引结构

索引-索引结构 1. 概述2. 二叉树3. B-Tree4. BTree5. Hash 1. 概述 MySQL的索引是在存储引擎层实现的&#xff0c;不同的存储引擎有不同的索引结构&#xff0c;主要包含以下几种&#xff1a; 上述是MySQL中所支持的所有的索引结构&#xff0c;下面展示不同的存储引擎对于索引…

JDK下载安装

资源展示 安装说明 傻瓜式安装&#xff0c;下一步即可。建议&#xff1a;安装路径不要有中文或者空格等特殊符号。本套课程会同时安装JDK8 和 JDK17&#xff0c;并以JDK17为默认版本进行讲解。 安装步骤 &#xff08;1&#xff09;双击jdk-17_windows-x64_bin.exe文件&#…

【Eureka详细讲解】

Eureka介绍和使用 1. Eureka 介绍2. Eureka 的主要特点3. 使用3.1 设置 Eureka Server3.2 设置 Eureka Client3.3 Eureka Server 高可用配置 1. Eureka 介绍 Eureka 是由 Netflix 开源的一种服务发现解决方案&#xff0c;它是 Netflix OSS 套件中的一个组件&#xff0c;经常用…

8-pytorch-损失函数与反向传播

b站小土堆pytorch教程学习笔记 根据loss更新模型参数 1.计算实际输出与目标之间的差距 2.为我们更新输出提供一定的依据&#xff08;反向传播&#xff09; 1 MSEloss import torch from torch.nn import L1Loss from torch import nninputstorch.tensor([1,2,3],dtypetorch.fl…

(只需三步)免费使用知网的攻略

通过浙江图书馆可以进入知网&#xff0c;并且查看与下载都是免费的。 &#xff08;只需要三步&#xff0c;很简单的。&#xff09; 第一步&#xff1a;注册浙江图书馆账号 打开zfb&#xff0c;搜索“浙江图书馆”小程序&#xff0c;进入个人中心->办理读者证&#xff0c;…

不同尺度下的网络控制方式

《三国演义》和《长安十二时辰》有什么不同&#xff1f; 关羽败走麦城&#xff0c;远在千里之外的刘备收到两个信号&#xff0c;一个需要 “星夜驰援”&#xff0c;紧接着 “二弟休矣”&#xff0c;三国的故事在东亚大陆展开&#xff0c;地理尺度巨大&#xff0c;星夜不星夜其…

PHP语言检测用户输入密码及调用Python脚本

现在有一份计算流体力学N-S方程的Python脚本&#xff0c;想要在用户登录网站后可以可以运行该脚本&#xff0c;然后将脚本运行后绘制的图片显示在用户网页上。 建一个名为N_S.py的python脚本文件&#xff0c;这个脚本在生成图像后会自行关闭&#xff0c;随后将图片保存在指定的…

一篇超级最全的python基础篇

1.数据类型和变量 Python使用缩进来组织代码块,一般使用4个空格的缩进.使用#来注释一行,其他每一行都是一个语句,当语句以冒号:结尾时,缩进的语句视为代码块.Python对大小写敏感. 1.1 整数 Python可以处理任意大小的整数,包括负整数,写法与数学上写法一致,例如:-100.如果用十六…

【文本编辑器,哪款适合你?】讲解

文本编辑器&#xff0c;哪款适合你? 文本编辑器介绍 文本编辑器介绍 电脑使用者在选择文本编辑器时&#xff0c;应该考虑以下几个方面&#xff1a; 需求&#xff1a;你是需要进行基本的文字处理工作&#xff0c;比如写作业或者制作报告&#xff0c;还是需要使用到高级功能&am…

BIO实战、NIO编程与直接内存、零拷贝深入辨析

BIO实战、NIO编程与直接内存、零拷贝深入辨析 长连接、短连接 长连接 socket连接后不管是否使用都会保持连接状态多用于操作频繁&#xff0c;点对点的通讯&#xff0c;避免频繁socket创建造成资源浪费&#xff0c;比如TCP 短连接 socket连接后发送完数据后就断开早期的http服…

简单上手若依框架

简介 若依是一个基于SpringBoot&#xff0c;Shiro&#xff0c;Mybatis的权限后台管理系统官网文档&#xff1a;介绍 | RuoYi源码 前后端不分离 RuoYi: &#x1f389; 基于SpringBoot的权限管理系统 易读易懂、界面简洁美观。 核心技术采用Spring、MyBatis、Shiro没有任何其它重…

InfluxDB的常用数据操作

1.插入语句 # INSERT语句用于向数据库中插入数据点&#xff08;数据行&#xff09;。 # 这些数据点包含时间戳、测量&#xff08;measurement&#xff09;、标签&#xff08;tags&#xff09;和字段&#xff08;fields&#xff09;等信息。 # 以下是INSERT语句的基本语法 INSE…

C++面试:内存溢出、内存泄漏的原因与解决

目录 内存溢出&#xff08;Memory Overflow&#xff09; 内存溢出介绍 解决内存溢出问题的方法 内存泄漏&#xff08;Memory Leak&#xff09; 内存泄露基础 解决内存泄漏问题的方法 内存溢出&#xff08;Memory Overflow&#xff09; 内存溢出介绍 内存溢出是指程序在执…

第6.4章:StarRocks查询加速——Colocation Join

目录 一、StarRocks数据划分 1.1 分区 1.2 分桶 二、Colocation Join实现原理 2.1 Colocate Join概述 2.2 Colocate Join实现原理 三、应用案例 注&#xff1a;本篇文章阐述的是StarRocks-3.2版本的Colocation Join 官网文章地址&#xff1a; Colocate Join | StarRoc…

Rust所有权--与go对比学

如何拿返回值&#xff0c;如何不传递所有权就更改原值&#xff1f;如果想操作更改元变量要怎么做呢&#xff1f; 分别执行以下go代码&#xff1a; func main() {var a 10//calc1(a)//a calc_return(a)calc2(&a)a 100calc3(&a)fmt.Println(a) } func calc1(num int…

SQL Server 连接池相关内容

查看最大连接数 SELECT MAX_CONNECTIONS查看指定数据库的连接数 SELECT * FROM master.dbo.sysprocesses WHERE dbid IN ( SELECT dbid FROM master.dbo.sysdatabases WHERE NAMEDB_WMS_KZJ )获取当前SQL服务器所有的连接详细信息 SELECT * FROM sysprocesses获取自上次启动…

五大方法教你如何分分钟构造百万测试数据!

在测试的工作过程中&#xff0c;很多场景是需要构造一些数据在项目里的&#xff0c;方便测试工作的进行&#xff0c;构造的方法有很多&#xff0c;难度和技术深度也不一样。本文提供方法供你选择。 在测试的工作过程中&#xff0c;很多场景是需要构造一些数据在项目里的&#…

Centos服务器部署前后端项目

目录 准备工作1. 准备传输软件2. 连接服务器 部署Mysql1.下载Mysql(Linux版本)2. 解压3. 修改配置4. 启动服务另一种方法Docker 部署后端1. 在项目根目录中创建Dockerfile文件写入2. 启动 部署前端1. 在项目根目录中创建Dockerfile文件写入2. 启动 准备工作 1. 准备传输软件 …