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

网站开发工具的是什么查数据的网站有哪些

网站开发工具的是什么,查数据的网站有哪些,门户网站建设说明书,浙江省建设信息港官网首页1、EhCache介绍 在查询数据的时候,数据大多来自于数据库,我们会基于SQL语句与数据库交互,数据库一般会基于本地磁盘IO将数据读取到内存,返回给Java服务端,我们再将数据响应给前端,做数据展示。 但是MySQL…

1、EhCache介绍

在查询数据的时候,数据大多来自于数据库,我们会基于SQL语句与数据库交互,数据库一般会基于本地磁盘IO将数据读取到内存,返回给Java服务端,我们再将数据响应给前端,做数据展示。

但是MySQL这种关系型数据库查询数据相对比较慢,因为有磁盘IO,或者是全盘扫描的风险,在针对一些热点数据时,会对MySQL造成比较大的压力,此时我们可以采用缓存的方式来解决。

而缓存又分为很多种,相对服务端角度来说,可以采用Redis和JVM这两种方式。

Redis不必多说,直接基于基于内存读写,并发读写的并发能力特别强,所以很多时间,在分布式或者微服务的项目中,为了保证数据一致性,我们会采用Redis来实现缓存。

但是在一些单体项目,我们可以采用JVM级别的缓存,比如直接采用框架自带的,例如Hibernate的缓存,MyBatis的缓存,或者是Guava提供的Cache,以及今儿要玩的EhCache。

还有一种情况可以采用JVM缓存,在分布式环境下,如果并发特别大,Redis也扛不住,这是我们可以将数据平均的分散在各个节点的JVM缓存中,并且设置一个较短的生存时间,这样就可以减缓Redis的压力,从而解决热点数据Redis扛不住的问题

同时EhCache也是Hibernate框架默认使用的缓存组件实现二级缓存。类似MyBatis,就直接用的HashMap。

2、引入EhCache

官网:http://www.ehcache.org

通过后缀就可以看出EhCache是开源的组件。

EhCache除了开源,还有可以几乎0成本和Spring整合的有点,毕竟现在Java项目大多都是基于Spring方式构建的,这也可以让我们在使用EhCache的时候更加方便。

这里还是单独的使用EhCache来感受一下,其实使用方式和HashMap的put和get的方式类似,不过EhCache提供了更加丰富的功能。

EhCache有2.x和3.x两个常用的大版本,两个版本API差异巨大,这里咱们以3.x为讲解的内容应用

官方入门文档:
Ehcache 3.10 Documentation

        <!-- ehcache依赖   --><dependency><groupId>org.ehcache</groupId><artifactId>ehcache</artifactId><version>3.8.1</version></dependency><dependency><groupId>net.sf.ehcache</groupId><artifactId>ehcache</artifactId><version>2.10.6</version></dependency>

3、复制配置文件

  • 复制xml文件

图片alt

<!-- Ehcache2.x的变化(取自https://github.com/springside/springside4/wiki/Ehcache) -->
<!-- 1)最好在ehcache.xml中声明不进行updateCheck -->
<!-- 2)为了配合BigMemory和Size Limit,原来的属性最好改名 -->
<!--   maxElementsInMemory->maxEntriesLocalHeap -->
<!--   maxElementsOnDisk->maxEntriesLocalDisk -->
<ehcache><diskStore path="java.io.tmpdir"/><defaultCachemaxElementsInMemory="1000"eternal="false"timeToIdleSeconds="60"timeToLiveSeconds="60"overflowToDisk="false"/><cache name="myCache"maxElementsOnDisk="20000"maxElementsInMemory="2000"eternal="true"overflowToDisk="true"diskPersistent="true"/><cache name="myCache2"maxElementsOnDisk="20000"maxElementsInMemory="2000"eternal="true"overflowToDisk="true"diskPersistent="true"/>
</ehcache>
<!--
<diskStore>==========当内存缓存中对象数量超过maxElementsInMemory时,将缓存对象写到磁盘缓存中(需对象实现序列化接口)
<diskStore path="">==用来配置磁盘缓存使用的物理路径,Ehcache磁盘缓存使用的文件后缀名是*.data和*.index
name=================缓存名称,cache的唯一标识(ehcache会把这个cache放到HashMap里)
maxElementsOnDisk====磁盘缓存中最多可以存放的元素数量,0表示无穷大
maxElementsInMemory==内存缓存中最多可以存放的元素数量,若放入Cache中的元素超过这个数值,则有以下两种情况1)若overflowToDisk=true,则会将Cache中多出的元素放入磁盘文件中2)若overflowToDisk=false,则根据memoryStoreEvictionPolicy策略替换Cache中原有的元素
eternal==============缓存中对象是否永久有效,即是否永驻内存,true时将忽略timeToIdleSeconds和timeToLiveSeconds
timeToIdleSeconds====缓存数据在失效前的允许闲置时间(单位:秒),仅当eternal=false时使用,默认值是0表示可闲置时间无穷大,此为可选属性即访问这个cache中元素的最大间隔时间,若超过这个时间没有访问此Cache中的某个元素,那么此元素将被从Cache中清除
timeToLiveSeconds====缓存数据在失效前的允许存活时间(单位:秒),仅当eternal=false时使用,默认值是0表示可存活时间无穷大即Cache中的某元素从创建到清楚的生存时间,也就是说从创建开始计时,当超过这个时间时,此元素将从Cache中清除
overflowToDisk=======内存不足时,是否启用磁盘缓存(即内存中对象数量达到maxElementsInMemory时,Ehcache会将对象写到磁盘中)会根据标签中path值查找对应的属性值,写入磁盘的文件会放在path文件夹下,文件的名称是cache的名称,后缀名是data
diskPersistent=======是否持久化磁盘缓存,当这个属性的值为true时,系统在初始化时会在磁盘中查找文件名为cache名称,后缀名为index的文件这个文件中存放了已经持久化在磁盘中的cache的index,找到后会把cache加载到内存要想把cache真正持久化到磁盘,写程序时注意执行net.sf.ehcache.Cache.put(Element element)后要调用flush()方法
diskExpiryThreadIntervalSeconds==磁盘缓存的清理线程运行间隔,默认是120秒
diskSpoolBufferSizeMB============设置DiskStore(磁盘缓存)的缓存区大小,默认是30MB
memoryStoreEvictionPolicy========内存存储与释放策略,即达到maxElementsInMemory限制时,Ehcache会根据指定策略清理内存共有三种策略,分别为LRU(最近最少使用)、LFU(最常用的)、FIFO(先进先出)
-->
  • 修改springmvc.xml文件

图片alt

4、通过注解使用ehcache

  • 服务接口
package com.shenmazong.zg2.service;import java.util.HashMap;/*** @author 军哥* @version 1.0* @description: 缓存接口* @date 2023/10/15 19:24*/public interface EhCacheService {public HashMap<String, Object> createCache(String key, String value);public HashMap<String, Object> getCache(String key);public void delCache(String key);
}
  • 服务接口实现
package com.shenmazong.zg2.service.impl;import com.shenmazong.zg2.service.EhCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;import java.util.HashMap;/*** @author 军哥* @version 1.0* @description: TODO* @date 2023/10/15 19:26*/@Service
@Slf4j
public class EhCacheServiceImpl implements EhCacheService {@Override@Cacheable(value = "myCache", key = "'EhCacheServiceImpl'+#key")public HashMap<String, Object> createCache(String key, String value) {log.info("createCache:"+key+"~~~~~");HashMap<String, Object> map = new HashMap<>();map.put("name", "冯刚刚");map.put("age", "18岁");map.put(key, value);return map;}@Override@Cacheable(value = "myCache", key = "'EhCacheServiceImpl'+#key")public HashMap<String, Object> getCache(String key) {return null;}@Override@CacheEvict(value = "myCache", key = "'EhCacheServiceImpl'+#key")public void delCache(String key) {log.info("delCache:"+key+"~~~~~");return;}
}
  • 缓存控制层
package com.shenmazong.zg2.controller;import com.shenmazong.zg2.service.EhCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** @author 军哥* @version 1.0* @description: 缓存控制类* @date 2023/10/15 19:46*/@RestController
@RequestMapping(value = "/cache")
public class EhCacheController {@AutowiredEhCacheService ehCacheService;@PostMapping(value = "/create")public Object create() {return ehCacheService.createCache("name", "张飞");}@PostMapping(value = "/get")public Object get() {return ehCacheService.getCache("name");}@PostMapping(value = "/delete")public Object delete() {ehCacheService.delCache("name");return "OK";}}
  • 删除所有缓存
    @Override@CacheEvict(value = "myCache", allEntries = true)public void delCacheAll() {}

5、通过注解使用ehcache

package com.shenmazong.controller;import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;@Controller
@Slf4j
@RequestMapping(value = "/eh")
public class EhController {@AutowiredEhCacheCacheManager cacheManager;/*** 放入缓存* @param code* @return*/@GetMapping(value = "/put")@ResponseBodypublic Object put(@RequestParam("code") String code) {cacheManager.getCache("myCache").put("userCode", code);return "OK";}/*** 从缓存中取数据* @return*/@GetMapping(value = "/get")@ResponseBodypublic Object get() {String userCode = cacheManager.getCache("myCache").get("userCode", String.class);if(userCode != null) {System.out.println(userCode);return userCode;}return "NO DATA";}/*** 从缓存中删除数据* @return*/@GetMapping(value = "/del")@ResponseBodypublic Object del() {cacheManager.getCache("myCache").evict("userCode");return "OK";}/*** 删除所有缓存* @return*/@GetMapping(value = "/delAll")public Object delAll() {cacheManager.getCache("myCache").clear();return "OK";}}

文章转载自:
http://sociogenetic.mnqg.cn
http://auscultatory.mnqg.cn
http://pill.mnqg.cn
http://toponymy.mnqg.cn
http://multifoil.mnqg.cn
http://mesopelagic.mnqg.cn
http://inhabitance.mnqg.cn
http://reappearance.mnqg.cn
http://fjp.mnqg.cn
http://baa.mnqg.cn
http://sensitive.mnqg.cn
http://transmutation.mnqg.cn
http://verst.mnqg.cn
http://egghead.mnqg.cn
http://nicotinic.mnqg.cn
http://filariid.mnqg.cn
http://trichinous.mnqg.cn
http://slovakian.mnqg.cn
http://toise.mnqg.cn
http://manuduction.mnqg.cn
http://relaxant.mnqg.cn
http://reflectivity.mnqg.cn
http://cem.mnqg.cn
http://nitty.mnqg.cn
http://chalcenteric.mnqg.cn
http://conform.mnqg.cn
http://manchu.mnqg.cn
http://granular.mnqg.cn
http://putrescibility.mnqg.cn
http://fatigueless.mnqg.cn
http://huzoor.mnqg.cn
http://lingual.mnqg.cn
http://cooly.mnqg.cn
http://logistic.mnqg.cn
http://desegregation.mnqg.cn
http://chinovnik.mnqg.cn
http://copita.mnqg.cn
http://readdress.mnqg.cn
http://keef.mnqg.cn
http://alibi.mnqg.cn
http://ependyma.mnqg.cn
http://mothy.mnqg.cn
http://come.mnqg.cn
http://proteinate.mnqg.cn
http://exegetics.mnqg.cn
http://noncommercial.mnqg.cn
http://pyrotechnic.mnqg.cn
http://upsurge.mnqg.cn
http://java.mnqg.cn
http://counterirritant.mnqg.cn
http://discaire.mnqg.cn
http://mythologer.mnqg.cn
http://faddish.mnqg.cn
http://laredo.mnqg.cn
http://hophead.mnqg.cn
http://cableship.mnqg.cn
http://tampa.mnqg.cn
http://kinabalu.mnqg.cn
http://notornis.mnqg.cn
http://antifederalism.mnqg.cn
http://nuptiality.mnqg.cn
http://interpretive.mnqg.cn
http://sleeve.mnqg.cn
http://nab.mnqg.cn
http://rhetian.mnqg.cn
http://pricewise.mnqg.cn
http://favourite.mnqg.cn
http://unreservedly.mnqg.cn
http://tantalise.mnqg.cn
http://sized.mnqg.cn
http://carving.mnqg.cn
http://fussily.mnqg.cn
http://besmirch.mnqg.cn
http://calputer.mnqg.cn
http://easternmost.mnqg.cn
http://valor.mnqg.cn
http://jiff.mnqg.cn
http://decadent.mnqg.cn
http://goods.mnqg.cn
http://trone.mnqg.cn
http://eulogy.mnqg.cn
http://baseballer.mnqg.cn
http://preferences.mnqg.cn
http://tanling.mnqg.cn
http://congruous.mnqg.cn
http://benfactress.mnqg.cn
http://mountebankery.mnqg.cn
http://hqmc.mnqg.cn
http://hemoglobinopathy.mnqg.cn
http://underpitch.mnqg.cn
http://almirah.mnqg.cn
http://circumvallate.mnqg.cn
http://cystoscopy.mnqg.cn
http://kru.mnqg.cn
http://washout.mnqg.cn
http://begrime.mnqg.cn
http://unconducive.mnqg.cn
http://wrist.mnqg.cn
http://semiarid.mnqg.cn
http://deficient.mnqg.cn
http://www.dt0577.cn/news/94536.html

相关文章:

  • 花生壳域名可以做网站域名吗googleplay安卓版下载
  • 丹徒区建设局网站凡科建站官网登录
  • 成立一个网站软件需要多少钱丈哥seo博客
  • 哈尔滨网站建设服务公司淘宝搜索关键词查询工具
  • wordpress 微信登录关键词排名优化顾问
  • 重庆h5建站模板百度线上推广
  • 安阳网络科技有限公司西安关键字优化哪家好
  • 公众号自己做电影网站在哪里找软件开发公司
  • 网站改版死链接app推广方案怎么写
  • 论坛备案网站名称优化大师怎么提交作业
  • 政务网络及网站建设郑州网络营销公司排名
  • 动态网站如何做排行榜前十名
  • 天琥设计培训虞城seo代理地址
  • 深圳网站的优化网址注册
  • 完整的网站建设新东方托福班价目表
  • 简述商务网站建设步骤电商详情页模板免费下载
  • 合肥高端网站建设公司外链相册
  • 做网站服务器 自己电脑还是租京东关键词优化技巧
  • 网络推广优化网站哈尔滨网站建设
  • 垂直门户网站的盈利模式探讨网推团队
  • 重庆网站建设首选卓光网站排名费用
  • 网站兼容设置网站推广服务
  • 怎样在线做网站404软文写手接单平台
  • 提升学历选什么专业比较好外贸seo网站
  • 什么软件可以做网站html今日新闻热点
  • dz可以做视频网站吗百度推广最简单方法
  • 企业网站的建设毕业论文免费网站模板库
  • 石河子网站建设搜索引擎优化的要点
  • 网站架构策划书北京seo公司wyhseo
  • 统计网站怎么做百度排行榜风云榜小说