SpringBoot学习笔记【part14】Spring Cache + Redis 集成缓存数据

IsaacSim环境配置之配置本地资产包 摘要:Isaac Sim官方资产文件默认从美国服务器下载速度慢,影响开发体验。建议下载本地资产包并配置本地资源源。具体步骤包括:1) 下载资产包并解压;2) 修改Isaac Sim安装路径下的配置文件,添加本地资产路径配置,包括机器人、人物、环境等各类资源目录。配置完成后可显著提升资产加载速度,改善开发效率。文中提供了详细的配置文件修改示例和截图说明。 阅读详情

Spring Cache 是一个非常优秀的缓存组件,方便切换各种底层Cache(如:redis)
使用Spring Cache的好处:

  1. 提供基本的Cache抽象,方便切换各种底层Cache;
  2. 通过注解Cache可以实现类似于事务一样,缓存逻辑透明的应用到我们的业务代码上,且只需要更少的代码就可以完成;
  3. 提供事务回滚时也自动回滚缓存;
  4. 支持比较复杂的缓存逻辑。

项目集成Spring Cache + Redis,步骤如下。

第一步,添加依赖

<!-- redis -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<!-- spring2.X集成redis所需common-pool2-->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
    <version>2.6.0</version>
</dependency>

第二步,配置application.properties

spring.redis.host=192.168.3.100
spring.redis.port=6379
spring.redis.database= 0
spring.redis.timeout=1800000

spring.redis.lettuce.pool.max-active=20
spring.redis.lettuce.pool.max-wait=-1
#最大阻塞等待时间(负数表示没限制)
spring.redis.lettuce.pool.max-idle=5
spring.redis.lettuce.pool.min-idle=0

第三步,添加配置类

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
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.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.lang.reflect.Method;  
import java.time.Duration;


@Configuration
@EnableCaching
public class RedisConfig {

    /**
     * 1.自定义key规则(自定义key为类名拼接方法名拼接参数名)
     * @return
     */
    @Bean
    public KeyGenerator keyGenerator() {
        return new KeyGenerator() {
            @Override
            public Object generate(Object target, Method method, Object... params) {
                StringBuilder sb = new StringBuilder();
                sb.append(target.getClass().getName());
                sb.append(method.getName());
                for (Object obj : params) {
                    sb.append(obj.toString());
                }
                return sb.toString();
            }
        };
    }

    /**
     * 2.设置RedisTemplate规则
     * @param redisConnectionFactory
     * @return
     */
    @Bean
    public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);

        //解决查询缓存转换异常的问题
        ObjectMapper om = new ObjectMapper();
        // 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        // 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        jackson2JsonRedisSerializer.setObjectMapper(om);

        //序列号key value
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);

        redisTemplate.afterPropertiesSet();
        return redisTemplate;
    }

    /**
     * 3.设置CacheManager缓存规则
     * @param factory
     * @return
     */
    @Bean
    public 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))
                .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
                .disableCachingNullValues();

        RedisCacheManager cacheManager = RedisCacheManager.builder(factory)
                .cacheDefaults(config)
                .build();
        return cacheManager;
    }
}

@EnableCaching 注解用于开启缓存,并配置Redis缓存管理器。@EnableCaching 将触发后置处理器,,检查每一个 Spring bean 的 public 方法是否存在缓存注解。如果找到方法有缓存注解,则自动创建一个代理拦截方法调用和处理相应的缓存行为。

第四步,使用Spring Cache

常用缓存标签注解

① @Cacheable (查)

根据方法对其返回结果进行缓存,下次请求时,如果缓存存在,则直接读取缓存数据返回;如果缓存不存在,则执行方法,并把返回的结果存入缓存中。一般用在查询方法上。

参数说明
value缓存名,必填,它指定了你的缓存存放在哪块命名空间
cacheNames与 value 差不多,二选一即可
key可选属性,可以使用 SpEL 标签自定义缓存的key
keyGenerator指定自定义key规则生成器

② @CachePut (增)

使用该注解标志的方法,每次执行时会将结果存入指定的缓存中。其他方法可以直接从响应的缓存中读取缓存数据,而不需要再去查询数据库。一般用在新增方法上。

参数说明
value缓存名,必填,它指定了你的缓存存放在哪块命名空间
cacheNames与 value 差不多,二选一即可
key可选属性,可以使用 SpEL 标签自定义缓存的key
keyGenerator指定自定义key规则生成器

③ @CacheEvict (删、改)

使用该注解标志的方法,会清空指定的缓存,让下次查操作时再自动更新最新的缓存。一般用在更新或者删除方法上。

参数说明
value缓存名,必填,它指定了你的缓存存放在哪块命名空间
cacheNames与 value 差不多,二选一即可
key可选属性,可以使用 SpEL 标签自定义缓存的 key
allEntries是否清空所有缓存,默认为 false。如果指定为 true,则方法调用后将立即清空所有的缓存
beforeInvocation是否在方法执行前就清空,默认为 false。如果指定为 true,则在方法执行前就会清空缓存

第五步,编码并测试

注:在后端架构中,缓存的处理应该放在 Service 层,也就是以上 3 个注解应该标记在 Service 方法上。

启动服务器测试,成功写入 redis。

在这里插入图片描述

记录:
        在测试过程中碰到一个问题,启动 Spring Cache 后,查询方法将不执行了。经过排查发现后台报错 Unable to connect to 192.168.3.100:6379 ,这个错误时因为redis 默认端口号 6379 在Linux防火墙中不允许进行远程连接。
        需要执行如下Linux命令 /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT 在防火墙中开启 6379 端口的远程服务。

InVEST模型 | HAbitat quality模块计算生境质量  本文详细介绍使用InVEST模型中HAbitat quality模块计算生境质量,包含各个参数的含义、所需数据、数据处理以及需要各个参数注意的地方等过程。 阅读详情

相关推荐

Jetson编译安装pycuda

可使用nvcc --version查看是否有信息输出,若没有,且安装cuda的情况下,需要手动将CUDA 的路径添加到环境变量中。编译生成_pvt_struct.cpython-38-aarch64-linux-gnu.so文件。基于jetson orin nano jetpack512模块上安装pycuda。4、获取pycuda源码(版本根据实际情况获取)2、进入conda环境并安装cuda工具包。9、若未检测出来需要清除并强制编译。7、编译成功后安装pycuda。5、配置编译并设置环境变量。

qq_48175141的博客 972

Springboot整合Prometheus+Grafana自定义指标监控

prometheus自定义指标监控,监控大屏展示

LMC技术人生专栏 1165

【雷达仿真 | FMCW TDMA-MIMO毫米波雷达信号处理仿真(可修改为DDMA-MIMO)】

1、FMCW叫做调频连续波,调频连续波有步进调频连续波(SFMCW)、线性调频连续波(LFMCW),以及其他非线性调频连续波。LFMCW有锯齿波和三角波等等;锯齿波有恒定调制周期的锯齿波和非恒定周期的锯齿波。Introduction to mmwave sensing:FMCW radars.pdf和The fundamentals of millimeter wave sensors。2、MIMO是多输入多输出(Multiple input Multiple output),也就是多发多收。

【调皮连续波】雷达技术领域知识博主 1万+

spring-boot - autoconfig

autoconfg 默认加载的类 #Thu Mar 01 04:55:30 UTC 2018 org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic.NewRelicMetricsExportAutoConfiguration.Configuration= org.springframework.boot.actuate.autoconfigure.redis.RedisHealthIndicatorAutoConfigu

星辰一地的专栏 1334

COMSOL模拟CO2驱替CH4:多物理场耦合建模与工程应用详解

在非常规天然气开发与碳封存工程中,多孔介质内的渗流、吸附与岩石变形相互耦合,使得CO2驱替CH4的产能预测和CO2封存评估无法仅靠经验公式完成。以达西定律描述裂隙流动、以扩展Langmuir方程刻画竞争吸附、用应力-吸附-渗透率关系关联煤岩变形,是多物理场耦合数值模拟的核心路径。COMSOL Multiphysics凭借内置渗流、固体力学与组分传递接口,能够将这些机制整合为可参数化扫描的仿真模型,为注气压力、井距、渗透率演化等方案设计提供量化依据。围绕CO2驱替CH4模拟的建模流程、参数取法与结果判读,可形

weixin_29574585的博客 162

关于对鱼眼相机图片进行畸变校正的两种思路

鱼眼畸变主要表现为径向畸变(Radial Distortion),图像中心正常,边缘向外拉伸。畸变模型通常基于入射角θ\thetaθ(光线与光学轴夹角)和图像半径rrr的关系。等距投影(Equidistant Projection)rdfθrd​fθ,其中rdr_drd​为畸变图像半径,fff为焦距,θ\thetaθ为入射角。等立体角投影(Equisolid Angle Projection)rd2fsin⁡θ2rd​2fsinθ/2。

qq_45670407的博客 1546

Springboot整合SpringCache+Redis

Springboot整合SpringCache+Redis

SampsonKong的博客 2648

处理图数据, 安装“Pytorch“ + 图神经网络开源框架“PyG “+ “ogb“使用

"OGB" OSError: [WinError 127] 找不到指定的程序。1.[遇到这类问题往往跟torch安装的工具包(如torch-sparse,torch-scatter,torch-cluster)版本没对应上有关](https://blog.csdn.net/weixin_42358688/article/details/117433691)2.[OGB使用环境安装与依赖](https://ogb.stanford.edu/docs/home/)Data Loaders3.[torch-geo

Fuguir™的博客 3698

SpringBoot实现Redis缓存(SpringCache+Redis的整合)

数据库的数据是存储在硬盘上的,频繁访问性能较低。如果将一些需要频繁查询的热数据放到内存的缓存中,可以大大减轻数据库的访问压力。 SpringCache SpringCache提供基本的Cache抽象,并没有具体的缓存能力,需要配合具体的缓存实现来完成,目前SpringCache支持redis、ehcache、simple(基于内存)等方式来实现缓存。 <dependency> <groupId>org.springframework.boot</groupId>

user2025的博客 2万+

YOLOv8与Swin Transformer的完美结合:如何提升目标检测的精度与速度

Swin Transformer(Shifted Window Transformer)是一种新型的视觉Transformer架构,采用了局部窗口(Window)和局部窗口偏移(Shifted Window)的策略,极大减少了计算复杂度,同时保持了全局感知能力。局部窗口注意力:每个窗口内的元素进行自注意力计算,减少计算量。窗口偏移:通过在不同层次引入窗口偏移,增强了全局信息的交互。层级设计:通过堆叠多个层次的模块,逐渐捕捉不同尺度的特征。

shrgegrb的博客 2151

对角两对双差速轮AGV的平移、直行、转弯和原地旋转之PID控制

本示例将展示如何使用PID控制算法,控制具有对角线布置的两对双差速轮(左前和右后)的AGV,实现平移、直行、转弯和原地旋转等运动。通过对车辆的运动学和PID控制器的设计,我们可以精确地控制AGV的运动

xiaoc100200的博客 1510

SpringBoot整合Spring Cache实现Redis缓存

Spring Cache 是一个框架,实现了基于注解的缓存功能,只需要简单地加一个注解,就能实现缓存功能。Spring Cache 提供了一层抽象,底层可以切换不同的cache实现。具体就是通过 CacheManager 接口来统一不同的缓存技术。...

陈宝子的博客 1283

UG\NX二次开发 获取对象的层、颜色、隐藏状态、线宽、线型、高亮显示状态

获取对象的层、颜色、隐藏状态、线宽、线型、高亮显示状态。

王牌飞行员_里海的博客 1981

springbootCache和Redis缓存机制

简介 我想要开发一个社交网站,社交网站存储好友列表成为了开发过程中的一大难题。 如果我想要保存每一个用户的好友信息该怎么保存呢? 用用户的id对应着好友的id,这样一条信息就是一个好友关系映射图,这张关系表可能长下面这样 id user_id friend_id 1 1 2 2 1 一个用户的好友由friend_id记录,1号用户和2号用户互为好友,这样的记录虽然冗余但是不得不记录下来。但是这样有很大的弊端。 假设我有200个用户,每个用户有300个好友,那么这样一张表就会有200

m0_48159893的博客 4270

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

SpringBoot缓存通用方案(RedisCache缓存的实现)(二)

SpringBoot 很早就为我们提供好了Cache的操作规范,使用简洁方便,可以按需使用注解与编码的方式基础使用见之前编写的另一篇文章,此篇着重于写一个通用的方案SpringBootCache的使用(Redis实现)从统一规范化入手,避免过多的改造,首先自定义一个缓存的接口,提供新增缓存、更新缓存、删除缓存等通用的抽象方法,以用来满足缓存的key为入参、value为出参的格式、不需要子类实现的可以定义默认方法。

weixin_47224121的博客 2395

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SpringBoot系列——使用Spring Cache和Redis实现查询数据缓存

在现代应用程序中,查询缓存的使用已经变得越来越普遍。它不仅能够显著提高系统的性能,还能提升用户体验。缓存通过在内存中存储频繁访问的数据,减少对数据库或其他存储系统的访问,从而加快数据读取速度。在这篇文章中,我们将探讨缓存的基本概念、重要性以及如何使用Spring Cache和Redis实现查询数据缓存。缓存是一种临时存储机制,用于在内存中保存频繁访问的数据。它可以是硬件(如CPU缓存)或软件(如应用程序缓存)。缓存的主要目的是通过减少数据访问的延迟,提高系统的响应速度。临时性。

weixin_73588491的博客 6456

Spring Boot整合 Cache 以Redis服务 处理数据缓存

高速缓存的设计需要综合考虑容量、命中率、替换策略、一致性等因素。合理的高速缓存设计可以显著提高计算机系统的性能,降低对主存储器的访问延迟,提高数据的读取和写入速度,在大部分应用场景下都起到了至关重要的作用。

杨荧的优快云博客 2311

Spring Boot 整合Redis 缓存实现

在 Spring Boot 中,数据的管理存储依赖于Spring框架中cache相关的org.springframework.cache.Cache 和 org.springframework.cache.CacheManager 缓存管理器接口。如果程序中没有定义类型为 cacheManager 的Bean 组件或者是名为 cacheResolver的 cacheResolver緩在解析器,Spring Boot将尝试选择并启用以下缓存组件(按照指定的顺序)。

2301_82310799的博客 1693

Springboot——整合Redis和cache缓存

文章目录前言Spring Cache案例达到目的依赖引入配置文件配置后的文件目录编写测试类等基本代码初步测试,查看数据是否能被添加至Redis缓存cache注解测试和详解@Cacheable 注解@CacheConfig注解@CachePut 注解@CacheEvict 注解@Caching注解更细节的注解信息汇总命令@Cacheable/@CachePut/@CacheEvict 主要的参数SpEL上下文数据运算符参考资料Demo下载 前言 实际开发中,针对请求量大的数据并且频繁请求的数据信息,在不断的对

专注写bug 1107

SpringBoot快速上手——《四》:SpringBoot 集成Redis +SpringCache做缓存

SpringBoot 集成Redis +SpringCache做缓存 一.给user加缓存 1.首先创建springboot-redis-cache模块,并把springboot-restful-api的内容复制过来。 2.修改三层架构,即加service层 添加service.UserService接口,再创建实现类service.impl.UserServiceimpl,记得实现类要加上@S...

weixin_41254252的博客 398

springboot+Redis缓存讲解+案例+原理+整合(简单详细!)

一、缓存(Cache)介绍: 保存一些临时性的数据。常用的方法有两种JSR107规范和Spring自己定义的规范 JSP107的java规范: 麻烦,这个规范用的比较少,一般使用的都是Spring自己的缓存抽象。 java的cacheing定义了5个接口,分别是CacheProvider, CacheManager, Cache, Entry 和 Expiry。 1、CacheingProvider可以管理(创建、配置、获取、管理和控制)多个...

一个塑料袋 1832

SpringBoot 使用 Cache 集成 Redis做缓存保姆教程

Spring Cache是Spring框架提供的一种缓存解决方案,基于AOP原理,实现了基于注解的缓存功能,只需要简单地加一个注解就能实现缓存功能,对业务代码的侵入性很小。使用Spring Cache的方法很简单,只需要在方法上添加注解即可实现将方法返回数据存入缓存,以及清理缓存等注解的使用。SpEL是Spring框架提供的一种功能强大的表达式语言,它能够在运行时查询和操作对象图。

笑小枫 2756

SpringBoot:缓存 + 搭建Redis缓存环境

SpringBoot搭建Redis缓存 注解版的 mybatis @CacheConfig @Cacheable @CachePut:既调用方法,又更新缓存数据;同步更新缓存 @CacheEvict:缓存清除 @Caching:定义复杂的缓存规则 CacheManager管理多个Cache组件的,对缓存的真正CRUD操作在Cache组件中,每一个缓存组件有自己唯一一个名字; 搭建Redis缓存环境及测试 RedisTemplate 自定义CacheManager

ChinaDragon10的博客 1591

SpringBoot --- 缓存Cache/Redis

SpringBoot --- 缓存Cache1.依赖2.application.properties3.注解4.代码 有时间多研究一下这个包,spring-boot-autoconfigure 1.依赖 <!-- 基础依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g

百世经纶『一页書』 4105

SpringBoot集成Redis使用Cache缓存

使用SpringBoot集成Redis使用Cache缓存只要配置相应的配置类,然后使用Cache注解就能实现。

cuishujian_2003的博客 1466

SpringBootCache的使用(Redis实现)

众所周知,缓存一般在内存中存储,cpu对内存的调度效率要优于硬盘(时间快)我们通常使用空间换取时间,达到某种程度的时空平衡于是一般来讲使用缓存可以提高效率—>提升性能我这次使用缓存是目的是将数据库字典类查询的结果放入缓存,以便于提高字典类使用时查询的效率(注:我所用到的字典类一般不会更新,数据量也不大,占用内存不多,大多用于查询的操作,适合用做缓存,可以大大减少数据库的压力,在一定程度上提升性能)

weixin_47224121的博客 1029

Springboot与Redis Cache深度整合

目录 Springboot项目创建 Springboot与Redis整合 Springboot与Mybatis整合 Springboot与Cache整合使用 Redis作为mybatis二级缓存 Redis分布式session共享 Springboot项目创建 1.打开IDEA 创建工程 2.选择IDEA中Spring initilazier 3.设置自己的包命名规范 4.勾选Web -> Spring Web -> Next -> Finish创建工程 5.创建对应的文件夹,

GaoChenXi 1419
上一篇: Swagger2学习笔记——SpringBoot整合Swagger2进行接口测试
下一篇: Docker学习笔记【part1】概念与安装
Parker7
博客等级 码龄7年 18粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Parker7

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值