Mybatis配置分布式缓存

利用MyBatis自身本地缓存结合Redis实现分布式缓存 一、Redis分布式缓存的实现 1、什么是缓存? 计算机内存中的一段数据。 2、内存中数据特点 读写快 断电立即丢失 3、缓存解决了什么问题? 提高网站吞吐量(请求响应)提高, 网站运行效率快 缓存的存在是用来解决数据库访问压力 4、既然缓存能提高效率, 所有项目中都加缓存吗? 使用缓存时一定是数据库中数据极少发生修改, 更多用于查询情况, 比如地址, 省, 市, 等 5、本地缓存和分布式缓存的区别? 本地缓存 : 存在应用服务器内存中数据称之为本地缓存(Local Cache) 分布式缓 阅读详情

分布式缓存

对缓存数据进行集中管理使用分布式缓存框架 redis、memcached、ehcache等。mybatis无法实现分布式缓存,需要和其它分布式缓存框架进行整合。

不使用分布缓存,缓存的数据在各各服务单独存储,不方便系统 开发。所以要使用分布式缓存对缓存数据进行集中管理。


分布式缓存工作图

mybatis本身来说是无法实现分布式缓存的,所以要与分布式缓存框架进行整合。

mybatis整合分布式缓存ehcache

首先加入ehcache的jar包


上图为jar包。

在User.xml中加入一行代码

配置缓存

[html]  view plain  copy
  1. <cache type="org.mybatis.caches.ehcache.EhcacheCache"/>  
开启全局缓存配置

[html]  view plain  copy
  1. <settings>  
  2.         <setting name="cacheEnabled" value="true"/>  
  3. </settings>  
测试类

[java]  view plain  copy
  1. package cn.bj.mybatis.test;  
  2.   
  3. import java.io.IOException;  
  4. import java.io.InputStream;  
  5. import java.util.List;  
  6.   
  7. import org.apache.ibatis.io.Resources;  
  8. import org.apache.ibatis.session.SqlSession;  
  9. import org.apache.ibatis.session.SqlSessionFactory;  
  10. import org.apache.ibatis.session.SqlSessionFactoryBuilder;  
  11. import cn.bj.mybatis.model.IUserOperation;  
  12. import cn.bj.mybatis.model.User;  
  13. import cn.bj.mybatis.model.UserCustom;  
  14. import cn.bj.mybatis.model.UserQueryVO;  
  15.   
  16. public class MybatisTest {  
  17.     public static void main(String[] args){  
  18.         SqlSessionFactory sqlSessionFactory = null;  
  19.         SqlSession session1 = null;  
  20.         SqlSession session2 = null;  
  21.         SqlSession session3 = null;  
  22.         SqlSession session4 = null;  
  23.         String resource = "Configuration.xml";  
  24.         InputStream inputStream;  
  25.         try {  
  26.             inputStream = Resources.getResourceAsStream(resource);  
  27.             sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);  
  28.             session1 = sqlSessionFactory.openSession();  
  29.             session2 = sqlSessionFactory.openSession();  
  30.             session3 = sqlSessionFactory.openSession();  
  31.             session4 = sqlSessionFactory.openSession();  
  32.             IUserOperation userOperation1 = (IUserOperation)session1.getMapper(IUserOperation.class);  
  33.             IUserOperation userOperation2 = (IUserOperation)session2.getMapper(IUserOperation.class);  
  34.             IUserOperation userOperation3 = (IUserOperation)session3.getMapper(IUserOperation.class);  
  35.             IUserOperation userOperation4 = (IUserOperation)session4.getMapper(IUserOperation.class);  
  36.               
  37.             User user1 = (User)userOperation1.selectUser(5);  
  38.             System.out.println(user1.getId());  
  39.             System.out.println(user1.getUsername());  
  40.             session1.close();  
  41.               
  42.             User user2 = (User)userOperation2.selectUser(5);  
  43.             user2.setAge(34);  
  44.             userOperation2.updateUser(user2);  
  45.             session2.commit();  
  46.             session2.close();  
  47.               
  48.               
  49.             User user3 = (User)userOperation3.selectUser(5);  
  50.             System.out.println(user3.getId());  
  51.             System.out.println(user3.getUsername());  
  52.             session3.close();  
  53.             User user4 = (User)userOperation4.selectUser(5);  
  54.             System.out.println(user4.getId());  
  55.             System.out.println(user4.getUsername());  
  56.             session4.close();  
  57.               
  58.         } catch (IOException e) {  
  59.             e.printStackTrace();  
  60.         }finally{  
  61.               
  62.         }  
  63.           
  64.     }  
  65.   
  66. }  

看输出效果:

[plain]  view plain  copy
  1. DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.  
  2. DEBUG [main] - PooledDataSource forcefully closed/removed all connections.  
  3. DEBUG [main] - PooledDataSource forcefully closed/removed all connections.  
  4. DEBUG [main] - PooledDataSource forcefully closed/removed all connections.  
  5. DEBUG [main] - PooledDataSource forcefully closed/removed all connections.  
  6. DEBUG [main] - Configuring ehcache from ehcache.xml found in the classpath: file:/D:/workspace/MyBatisTest/bin/ehcache.xml  
  7. DEBUG [main] - Configuring ehcache from URL: file:/D:/workspace/MyBatisTest/bin/ehcache.xml  
  8. DEBUG [main] - Configuring ehcache from InputStream  
  9. DEBUG [main] - Ignoring ehcache attribute xmlns:xsi  
  10. DEBUG [main] - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation  
  11. DEBUG [main] - Disk Store Path: F:\develop\ehcache  
  12. DEBUG [main] - Creating new CacheManager with default config  
  13. DEBUG [main] - propertiesString is null.  
  14. DEBUG [main] - No CacheManagerEventListenerFactory class specified. Skipping...  
  15. DEBUG [main] - No BootstrapCacheLoaderFactory class specified. Skipping...  
  16. DEBUG [main] - CacheWriter factory not configured. Skipping...  
  17. DEBUG [main] - No CacheExceptionHandlerFactory class specified. Skipping...  
  18. DEBUG [main] - Initialized net.sf.ehcache.store.NotifyingMemoryStore for cn.bj.mybatis.model.IUserOperation  
  19. DEBUG [main] - Initialised cache: cn.bj.mybatis.model.IUserOperation  
  20. DEBUG [main] - CacheDecoratorFactory not configured for defaultCache. Skipping for 'cn.bj.mybatis.model.IUserOperation'.  
  21. DEBUG [main] - <span style="color:#ff0000;">Cache Hit Ratio [cn.bj.mybatis.model.IUserOperation]: 0.0</span>  
  22. DEBUG [main] - Opening JDBC Connection  
  23. DEBUG [main] - Created connection 28235257.  
  24. DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  25. DEBUG [main] - ==>  Preparing: select * from t_user where id = ?   
  26. DEBUG [main] - ==> Parameters: 5(Integer)  
  27. DEBUG [main] - <==      Total: 1  
  28. 5  
  29. kksskdk  
  30. DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  31. DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  32. DEBUG [main] - Returned connection 28235257 to pool.  
  33. DEBUG [main] - <span style="color:#ff6666;">Cache Hit Ratio [cn.bj.mybatis.model.IUserOperation]: 0.5</span>  
  34. DEBUG [main] - Opening JDBC Connection  
  35. DEBUG [main] - Checked out connection 28235257 from pool.  
  36. DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  37. DEBUG [main] - ==>  Preparing: update t_user set username=?,age=? where id=?   
  38. DEBUG [main] - ==> Parameters: kksskdk(String), 34(Integer), 5(Integer)  
  39. DEBUG [main] - <==    Updates: 1  
  40. DEBUG [main] - Committing JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  41. DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  42. DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  43. DEBUG [main] - Returned connection 28235257 to pool.  
  44. DEBUG [main] - <span style="color:#ff6666;">Cache Hit Ratio [cn.bj.mybatis.model.IUserOperation]: 0.3333333333333333</span>  
  45. DEBUG [main] - Opening JDBC Connection  
  46. DEBUG [main] - Checked out connection 28235257 from pool.  
  47. DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  48. DEBUG [main] - ==>  Preparing: select * from t_user where id = ?   
  49. DEBUG [main] - ==> Parameters: 5(Integer)  
  50. DEBUG [main] - <==      Total: 1  
  51. 5  
  52. kksskdk  
  53. DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  54. DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@1aed5f9]  
  55. DEBUG [main] - Returned connection 28235257 to pool.  
  56. DEBUG [main] - Cache Hit Ratio [cn.bj.mybatis.model.IUserOperation]: 0.5  
  57. 5  
  58. kksskdk  

命中率不小的。






PDPS16.0单机版与SPLMLicenseServer授权避坑指南:从安装到冲突解决 本文详细解析了PDPS16.0单机版的安装与授权流程,重点阐述了如何正确配置SPLMLicenseServer本地许可证服务器以实现软件激活。针对安装过程中常见的许可证冲突问题,提供了清晰的排查思路和解决方案,并介绍了通过设置环境变量等替代授权方法,帮助用户高效避坑,确保Tecnomatix Process Simulate顺利运行。 阅读详情

相关推荐

Yolov5实现道路裂缝检测

Yolov5实现道路裂缝检测 参考代码链接 Github代码链接 基于Pytorch的Yolov5道路裂缝检测程序运行说明。大家可以结合我的说明和原文说明使用,有问题欢迎询问。 文章目录Yolov5实现道路裂缝检测环境要求测试训练自己的数据集1.创建dataset.yaml文件2.创建标签文件3.组织文件路径4.选择模型5.开始训练 环境要求 Python 3.8或之后的版本 还要安装requirements.txt文件中所有依赖包,包括1.7及以上版本的torch $ pip install -r req

qq_26751379的博客 2万+

Mybatis之缓存详解

Mybatis之缓存详解

NestorBian的博客 1160

Android Profiler 帧率优化实战与性能调优

本文详细介绍了使用Android Profiler进行帧率优化与性能调优的实战方法。通过分析主线程状态、FPS曲线和渲染阶段耗时,精准定位卡顿根源,并提供减少过度绘制、优化绘制命令及改善资源使用的具体策略。文章结合电商、游戏等真实案例,帮助开发者有效解决卡顿问题,提升应用流畅度。

palm99的专栏 537

cachehelper java,初识EHCache缓存框架(2.x版本)

参考文档:关于EHCache3.x版本的使用详见此篇博客:Maven依赖:net.sf.ehcacheehcache2.10.31.独立使用在class根目录下加入配置文件ehcache1.xml.xsi:noNamespaceSchemaLocation = "http://ehcache.org/ehcache.xsd">maxEntriesLocalHeap = "10000"eter...

weixin_28747257的博客 611

hi3516cv610在PQStream上实现拉出图像,windows和板端操作记录

PQStream拉出图像

weixin_51838255的博客 729

PMD相位偏折术实战:如何用Python处理条纹图,让金属外壳的划痕无处遁形

本文详细介绍了PMD相位偏折术在金属外壳划痕检测中的应用,通过Python实现条纹图处理和局部特征增强技术,显著提升微小缺陷的检出率。文章涵盖从四步相移条纹图采集到形状图局部增强的完整流程,特别适合工业质检场景,帮助实现高精度、高效率的自动化检测。

weixin_29291573的博客 511

0基础学习Mybatis系列数据库操作框架——自定义分布式缓存器

继承org.apache.ibatis.cache.Cache接口,主要实现putObject和getObject方法。getObject返回null时,Mybatis会查询数据库;getObject返回对象时,Mybatis直接返回该对象,而不会查询数据库。当Mybatis查询数据库后,会调用putObject方法,让我们有保存数据到缓存的机会。实现org.apache.ibatis.builder.InitializingObject接口,让缓存器在构造时有我们自定义的初始化的机会。

方亮的专栏 1336

论文阅读《Eigen-GNN: A Graph Structure Preserving Plug-in for GNNs》

好久没看论文了,感觉好生疏 关于这篇文章的大致脉络,这篇文章已经介绍过了。

且视他人之疑目如盏盏鬼火,大胆地去走你的夜路 462

系列九、SpringBoot + MyBatis + Redis实现分布式缓存

缓存是计算机内存中的一段数据(PS:内存中的数据具有读写快、断电立即消失的特点),合理地使用缓存能够提高网站的吞吐量和运行效率,减轻数据库的访问压力。那么哪些数据适合缓存呢?使用缓存时,一定是数据库中的数据极少发生改变,更多用于查询的情况,例如:省、市、区、县、村等数据。

仰望星空,脚踏实地!安全感是自己给的,努力才是一辈子的安全感。 1545

新华硕笔记本ubuntu18.04双系统安装之后,wifi没有显示无法链接wifi

本来我以为跟简单安装一个wifi网卡的驱动就可以解决的问题,没想到花了我一早上的时候解决… 惭愧。 另外,本来是没打算写这篇博客的,但是我在搜索解决这个问题的过程中, 发现多人提出的解决方案跟我的都不一样,甚至我的解决方案都没有搜到相应的答案,还是只能靠自己啊。。 言归正传,还是说说怎么正确的安装wifi驱动吧! 1. wifi没有正确安装、或没有正确配置的表现 我的电脑现象: 有wifi图标, wifi设置上显示unaviable,无法搜索到任何wifi; 还有其他类似的表现,大家可以看看其他朋友的提

Ian的博客 1890

【WRF安装】WRF环境配置移植详细说明

【WRF安装】WRF环境配置移植详细说明

WW、forever的博客 820

Java-13 深入浅出 MyBatis 整合 Redis 实现分布式二级缓存:原理、配置与源码剖析

本文系统讲解 MyBatis 整合 Redis 实现分布式二级缓存的完整方案。基于 `org.mybatis.caches:mybatis-redis` 1.0.0-beta2(社区长期使用版本,官方 mybatis/redis-cache 仓库于 2026 年 4 月发布 1.0.0 正式版,内部已升级 Jedis 7.2.0)配合 Jedis 客户端,只需在 `xxxMapper.xml` 中通过 `<cache type="org.mybatis.caches.redis.RedisCache"/>`

谢谢你的喜欢 我们一起无限进步 2915

粒子群优化与蚁群算法求解多旅行商问题

它要求在给定一组城市和旅行商之间的距离矩阵的情况下,找到一条最优的路径方案,使得所有旅行商可以分别从起始城市出发,途径其他城市,并最终回到起始城市,同时总旅行距离达到最小。这两种算法都是基于群体智能的优化算法,在求解组合优化问题时具有较好的性能表现。假设有n个城市需要被m个旅行商访问,城市间的距离由距离矩阵D表示,其中D(i,j)表示第i个城市到第j个城市的距离。粒子群优化算法是一种基于群体智能的优化算法,其中的粒子代表了潜在的解,并通过模拟粒子在解空间中的移动来搜索最优解。一、多旅行商问题建模。

m0_47037246的博客 553

mybatis中二级缓存整合ehcache实现分布式缓存

mybatis自带二级缓存,但是这个缓存是单服务器工作,无法实现分布式缓存。那么什么是分布式缓存呢?假设现在有两个服务器1和2,用户访问的时候访问了1服务器,查询后的缓存就会放在1服务器上,假设现在有个用户访问的是2服务器,那么他在2服务器上就无法获取刚刚那个缓存,如下图所示: 为了解决这个问题,就得找一个分布式的缓存,专门用来存储缓存数据的,这样不同的服务器要缓存数据都往它那里存...

weixin_30772105的博客 122

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Mybatis学习(十四)mybatis框架下整合分布式缓存ehcache

分布式缓存 不使用分布缓存,缓存的数据在各各服务单独存储,不方便系统 开发。所以要使用分布式缓存对缓存数据进行集中管理。 分布式缓存工作图 mybatis本身来说是无法实现分布式缓存的,所以要与分布式缓存框架进行整合。 mybatis整合分布式缓存ehcache 首先加入ehcache的jar包 上图为jar包。 在User.xml中加入一行代码 配置缓存 开启全

蜗牛的专栏 9619

深度学习工具包 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")

MyBatis缓存机制学习

MyBatis缓存机制解析:本文详细介绍了MyBatis的一级缓存和二级缓存机制。一级缓存默认开启,作用域为SqlSession,基于HashMap存储;二级缓存需手动配置,作用域为Mapper级别,支持第三方缓存框架如EhCache。文章通过代码示例演示了缓存特性,测试了缓存生效条件,并详细解析了缓存标签属性(回收策略、刷新间隔等)。同时介绍了MyBatis与EhCache的整合步骤,包括依赖配置、参数调整等。最后分析了二级缓存的适用场景(读多写少、非敏感数据)和局限性(分布式环境不一致、缓存粒度粗等问题

ywl470812087的博客 12万+

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

ehcache 手动刷新缓存_MyBatis学习:MyBatis整合ehcache分布式缓存框架

昨天给大家分享了MyBatis中的二级缓存,那么二级缓存有没有什么弊端呢?是的,MyBatis的二级缓存无法实现分布式缓存,什么意思呢?就是说缓存的数据在自己的服务器上,假设现在有两个服务器A和B,用户访问的时候访问了A服务器,查询后的缓存就会放在A服务器上,假设现在有个用户访问的是B服务器,那么他在B服务器上就无法获取刚刚那个缓存,如下图所示: 所以我们为了解决这个问题,就得找一个分布式的缓存,...

weixin_39613208的博客 127

mybaits实现分布式缓存

一.背景描述 1.1 背景描述以及方案描述 mybatis中默认自带的二级缓存有个弊端,即无法实现分布式缓存,也就是说缓存的数据在自己的服务器上,假设现在有两个服务器A和B,用户访问的时候访问了A服务器,查询后的缓存就会放在A服务器上,假设现在有个用户访问的是B服务器,那么他在B服务器上就无法获取刚刚那个缓存,如下图所示: 针对以上问题,就得找一个分布式的缓存,专门用来存储缓存数据的,这样不同的服务器要缓存数据都往它那里存,取缓存数据也从它那里取,如下图所示: 这样就能解决上面所说的问题,为了.

健康平安的活着的专栏 333

MyBatis知识点复习-11一级缓存与二级缓存以及ehcache缓存

MyBatis知识点复习-11一级缓存与二级缓存

qq_44932835的博客 513

【MyBatis学习13】MyBatis中的二级缓存

1. 二级缓存的原理  前面介绍了,mybatis中的二级缓存是mapper级别的缓存,值得注意的是,不同的mapper都有一个二级缓存,也就是说,不同的mapper之间的二级缓存是互不影响的。为了更加清楚的描述二级缓存,先来看一个示意图:   从图中可以看出: sqlSession1去查询用户id为1的用户信息,查询到用户信息会将查询数据存储到该UserMapper的二级缓存中。

2万+

SpringBoot 下 mybatis 的缓存

背景: 说起 mybatis,作为 Java 程序员应该是无人不知,它是常用的数据库访问框架。与 Spring 和 Struts 组成了 Java Web 开发的三剑客--- SSM。当然随着 Spring Boot 的发展,现在越来越多的企业采用的是 SpringBoot + mybatis 的模式开发,我们公司也不例外。而 mybatis 对于我也仅仅停留在会用而已,没想过怎么去了解它,更不...

mengsofts的专栏 3826

Mybatis(五)——缓存

目录缓存简介 缓存简介 MyBatis系统中默认定义了两级缓存。 一级缓存和二级缓存。 默认情况下,只有一级缓存(SqlSession级别的缓存, 也称为本地缓存)开启。 二级缓存需要手动开启和配置,他是基于namespace级别的缓存。 为了提高扩展性。MyBatis定义了缓存接口Cache。我们 可以通过实现Cache接口来自定义二级缓存 mybatis中默认自带的二级缓存实现(P...

weixin_42412601的博客 360

mybatis---缓存

mybatis---缓存1、缓存介绍2、一级缓存3、二级缓存3.1、二级缓存初步使用3.2、cache的参数4、整合第三方缓存4.1、整合Windows版本的Redis缓存4.1.1、 在github上下载一个windows版本的redis:[windows版本的redis地址](https://github.com/MicrosoftArchive/redis/tags)。4.1.2、开始搭建 1、缓存介绍 MyBatis 内置了一个强大的事务性查询缓存机制,它可以非常方便地配置和定制。 为了使它更加强

qq_41931364的博客 837

3分钟搞懂MyBatis-Plus多级缓存:本地+分布式协同实战

你还在为数据库查询慢发愁?并发量一上来就卡顿?本文将带你掌握MyBatis-Plus的多级缓存策略,通过本地缓存(Local Cache)与分布式缓存(Distributed Cache)的协同工作,让查询性能提升10倍!读完你将学会: - 本地缓存的开启与优化配置 - 分布式缓存的集成方案 - 双缓存协同策略与一致性保障 - 实战案例:从0到1搭建多级缓存架构 ## 一、本地缓存:MyBat...

gitblog_00545的博客 736

mybatisplus 配置二级缓存

MyBatis-Plus二级缓存配置指南:包含基础配置和高级特性,支持本地和分布式(Redis)两种缓存方案。核心步骤:1)添加依赖;2)全局开启缓存;3)实体类实现序列化;4)Mapper配置缓存策略(XML或注解)。分布式环境推荐使用Redis缓存,可自定义JSON序列化优化性能。提供细粒度控制方法(禁用/刷新缓存)和验证测试方案,同时提醒注意BaseMapper方法缓存行为、分页查询和多表关联的特殊处理。合理配置可显著减少数据库访问,但需平衡缓存命中率与数据一致性。

果酱 の 博客 1014

MyBatis缓存策略之二级缓存

转自:https://blog.youkuaiyun.com/zmx729618/article/details/77991916   1. 二级缓存的原理 前面介绍了,mybatis中的二级缓存是mapper级别的缓存,值得注意的是,不同的mapper通常情况下有不同的namespace,就都有一个二级缓存,也就是说,不同的mapper之间的二级缓存是互不影响的。为了更加清楚的描述二级缓存,先来看一个...

【欢迎关注公众号:冬瓜白】 932
上一篇: LVSDR负载均衡
下一篇: java多线程的使用与原理
CookSjg
博客等级 码龄10年 1粉丝 12原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值