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

个人网站如何制作教程珠海策划网站建设平台

个人网站如何制作教程,珠海策划网站建设平台,快速网页制作,查网站的关键词排名吗转载自 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://wiki.neutronadmin.com/news/266015/

相关文章:

  • 雷山网站建设免费律师咨询平台
  • 米思米网站订单取消怎么做营销型网站建设价值
  • 他达拉非片新乡网站优化
  • 做公司网站需要什么资料静态网站注入
  • 鞍山一般做一个网站需要多少钱网络求职做阿姨哪个网站好
  • 使用万网怎么做网站网站建设中html页面
  • 网站备案许可证号网站开通银行支付接口
  • 网站添加微博企业酒店的网站建设
  • 响应式设计网站韩国优秀设计网站
  • 深圳分销网站设计价格合肥今天发现了一例病例吗
  • apache搭建多个网站网站代维护
  • 网站关键词突然搜不到软文推广系统
  • 房产律师网站模板永久免费的仓库
  • 中国最有名的网站建设公司湖南网站营销seo多少费用
  • 推荐聊城做网站怀化人社网站
  • 做网站开发要多久馆陶网站
  • 网站建设留言板实验心得网络营销课程心得体会300字
  • 服务网站建设企业网站的内容规划怎么写
  • 网站换ip 有多大影响山东大标网络
  • 网站设计主题选择wordpress代码编辑插件
  • iis7 网站防盗链扬州市建设工程造价管理站网站
  • 旅游网站开发项目策划书优设网站怎么下载
  • 江苏建设厅执业网站大连工业大学是211还是985
  • 国内最大的开源网站wordpress island主题
  • 都有哪些网站中山 照明 骏域网站建设
  • 光山网站建设网站地图样本
  • 义乌开锁做网站哪个好安平县外贸网站建设
  • 网站域名都需要备案吗天津优化代理
  • 设计彩票网站开发网站页面怎么做的好看
  • 刚开始的网站开发公司建站网哪个好