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

网站代理被抓建站之星收费版

网站代理被抓,建站之星收费版,昆明短视频制作公司,263企业邮箱后缀是什么转载自 Spring思维导图#xff0c;让Spring不再难懂#xff08;cache篇#xff09; 关于缓存 缓存是实际工作中非常常用的一种提高性能的方法。而在java中#xff0c;所谓缓存#xff0c;就是将程序或系统经常要调用的对象存在内存中#xff0c;再次调用时可以快速从内存…转载自 Spring思维导图让Spring不再难懂cache篇 关于缓存 缓存是实际工作中非常常用的一种提高性能的方法。而在java中所谓缓存就是将程序或系统经常要调用的对象存在内存中再次调用时可以快速从内存中获取对象不必再去创建新的重复的实例。这样做可以减少系统开销提高系统效率。 在增删改查中数据库查询占据了数据库操作的80%以上而非常频繁的磁盘I/O读取操作会导致数据库性能极度低下。而数据库的重要性就不言而喻了 数据库通常是企业应用系统最核心的部分数据库保存的数据量通常非常庞大数据库查询操作通常很频繁有时还很复杂 在系统架构的不同层级之间为了加快访问速度都可以存在缓存 spring cache特性与缺憾 现在市场上主流的缓存框架有ehcache、redis、memcached。spring cache可以通过简单的配置就可以搭配使用起来。其中使用注解方式是最简单的。 Cache注解 从以上的注解中可以看出虽然使用注解的确方便但是缺少灵活的缓存策略 缓存策略 TTLTime To Live 存活期即从缓存中创建时间点开始直到它到期的一个时间段不管在这个时间段内有没有访问都将过期 TTITime To Idle 空闲期即一个数据多久没被访问将从缓存中移除的时间 项目中可能有很多缓存的TTL不相同这时候就需要编码式使用编写缓存。 条件缓存 根据运行流程如下Cacheable将在执行方法之前( #result还拿不到返回值)判断condition如果返回true则查缓存  Cacheable(value  user, key  #id, condition  #id lt 10)   public User conditionFindById(final Long id)  如下CachePut将在执行完方法后#result就能拿到返回值了判断condition如果返回true则放入缓存 CachePut(value  user, key  #id, condition  #result.username ne zhang)   public User conditionSave(final User user)   如下CachePut将在执行完方法后#result就能拿到返回值了判断unless如果返回false则放入缓存即跟condition相反 CachePut(value  user, key  #user.id, unless  #result.username eq zhang)   public User conditionSave2(final User user)   如下CacheEvict beforeInvocationfalse表示在方法执行之后调用#result能拿到返回值了且判断condition如果返回true则移除缓存 CacheEvict(value  user, key  #user.id, beforeInvocation  false, condition  #result.username ne zhang)  public User conditionDelete(final User user)   小试牛刀综合运用 CachePut(value user, key #user.id)public User save(User user) {users.add(user);return user;}CachePut(value user, key #user.id)public User update(User user) {users.remove(user);users.add(user);return user;}CacheEvict(value user, key #user.id)public User delete(User user) {users.remove(user);return user;}CacheEvict(value user, allEntries true)public void deleteAll() {users.clear();}Cacheable(value user, key #id)public User findById(final Long id) {System.out.println(cache miss, invoke find by id, id: id);for (User user : users) {if (user.getId().equals(id)) {return user;}}return null;}配置ehcache与redis spring cache集成ehcachespring-ehcache.xml主要内容 dependencygroupIdnet.sf.ehcache/groupIdartifactIdehcache-core/artifactIdversion${ehcache.version}/version /dependency!-- Spring提供的基于的Ehcache实现的缓存管理器 --!-- 如果有多个ehcacheManager要在bean加上p:sharedtrue -- bean idehcacheManager classorg.springframework.cache.ehcache.EhCacheManagerFactoryBeanproperty nameconfigLocation valueclasspath:xml/ehcache.xml/ /beanbean idcacheManager classorg.springframework.cache.ehcache.EhCacheCacheManagerproperty namecacheManager refehcacheManager/property nametransactionAware valuetrue/ /bean!-- cache注解和spring-redis.xml中的只能使用一个 -- cache:annotation-driven cache-managercacheManager proxy-target-classtrue/spring cache集成redisspring-redis.xml主要内容 dependencygroupIdorg.springframework.data/groupIdartifactIdspring-data-redis/artifactIdversion1.8.1.RELEASE/version /dependency dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-pool2/artifactIdversion2.4.2/version /dependency dependencygroupIdredis.clients/groupIdartifactIdjedis/artifactIdversion2.9.0/version /dependency!-- 注意需要添加Spring Data Redis等jar包 -- descriptionredis配置/descriptionbean idjedisPoolConfig classredis.clients.jedis.JedisPoolConfigproperty namemaxIdle value${redis.pool.maxIdle}/property namemaxTotal value${redis.pool.maxActive}/property namemaxWaitMillis value${redis.pool.maxWait}/property nametestOnBorrow value${redis.pool.testOnBorrow}/property nametestOnReturn value${redis.pool.testOnReturn}/ /bean!-- JedisConnectionFactory -- bean idjedisConnectionFactory classorg.springframework.data.redis.connection.jedis.JedisConnectionFactoryproperty namehostName value${redis.master.ip}/property nameport value${redis.master.port}/property namepoolConfig refjedisPoolConfig/ /beanbean idredisTemplate classorg.springframework.data.redis.core.RedisTemplatep:connectionFactory-refjedisConnectionFactoryproperty namekeySerializerbean classorg.springframework.data.redis.serializer.JdkSerializationRedisSerializer/bean/propertyproperty namevalueSerializerbean classorg.springframework.data.redis.serializer.JdkSerializationRedisSerializer//propertyproperty namehashKeySerializerbean classorg.springframework.data.redis.serializer.JdkSerializationRedisSerializer//propertyproperty namehashValueSerializerbean classorg.springframework.data.redis.serializer.JdkSerializationRedisSerializer//property /bean!--spring cache-- bean idcacheManager classorg.springframework.data.redis.cache.RedisCacheManagerc:redisOperations-refredisTemplate!-- 默认缓存10分钟 --property namedefaultExpiration value600/property nameusePrefix valuetrue/!-- cacheName 缓存超时配置半小时一小时一天 --property nameexpiresmap key-typejava.lang.String value-typejava.lang.Longentry keyhalfHour value1800/entry keyhour value3600/entry keyoneDay value86400/!-- shiro cache keys --entry keyauthorizationCache value1800/entry keyauthenticationCache value1800/entry keyactiveSessionCache value1800//map/property /bean !-- cache注解和spring-ehcache.xml中的只能使用一个 -- cache:annotation-driven cache-managercacheManager proxy-target-classtrue/ 项目中注解缓存只能配置一个所以可以通过以下引入哪个配置文件来决定使用哪个缓存。 import resourceclasspath:spring/spring-ehcache.xml/ !-- import resourceclasspath:spring/spring-redis.xml/--当然可以通过其他配置搭配使用两个缓存机制。比如ecache做一级缓存redis做二级缓存。 更加详细的使用与配置可以参考项目中spring-shiro-training中有关spring cache的配置。 https://git.oschina.net/wangzhixuan/spring-shiro-training.git
http://www.huolong8.cn/news/123881/

相关文章:

  • 制作网页需要哪些技术国内seo公司排名
  • 网站收录目录源码江苏建筑工程网
  • 江苏省工程建设标准站网站交通网站建设
  • 福建网站建设服务软文编辑
  • 陕西省建设资格注册中心网站wordpress 插件player
  • 开发手机端网站模板下载游戏怎么做充值网站
  • 李志自己做网站网站红色
  • 长沙做网站开发大概价格昆明搭建微信网站哪家最优惠
  • 营销型网站规划建设的七大要素用户权限配置wordpress
  • 阿里云网站实名认证静态网站用什么做
  • 淘宝做网站被骗网页制作app手机版
  • 上海高端建站html做电子书网站
  • 站酷网怎么接单赚钱网站建设方案的摘要怎么写
  • 帝国网站管理系统后台eclassconfig.php不存在中国摄影网站十大排名
  • 网站系统流程图西安网阔云信息科技有限公司
  • 文库网站开发网站建设详细流
  • 通州设计网站建设phpcms学校网站模板
  • 临沂网站域名大宗商品现货交易平台
  • 上海 网站 备案wordpress img相对路径
  • 网站毕业设计开题报告把网站内容东西打出来怎么做
  • wordpress文章站网站开发与维护是干什么的
  • ssl正式申请后wordpress百度站长工具seo查询
  • 科普网站栏目建设方案企业邮箱下载安装
  • 建站服务网络公司珠海网站建设制作怎么收费
  • 关于网站建设项目收取费用如何跟客户沟通网站建设
  • 国内精品网站建设wordpress制作插件
  • 在线酒店预定网站制作北京海淀区官网
  • 微网站开发需要几个人江华网站建设
  • 专注扬中网站建设自定义网站主页设计
  • 网站界面设计的基本原则是什么三明鑫龙建设工程网站