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

96微信编辑器官网重庆百度seo整站优化

96微信编辑器官网,重庆百度seo整站优化,聊城阳谷网站建设,自己的卡盟网站怎么做分站java接口的查询如何能提高性能#xff0c;比每次都去数据库中查询要快的方案有了#xff0c;就是下面要介绍的。 一、添加依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-cache/artifactId…java接口的查询如何能提高性能比每次都去数据库中查询要快的方案有了就是下面要介绍的。 一、添加依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-cache/artifactId/dependencydependencygroupIdcom.github.ben-manes.caffeine/groupIdartifactIdcaffeine/artifactId/dependency 二、启动类上添加注解 org.springframework.cache.annotation.EnableCaching 三、配置 1、采用spring自带配置 ############# 缓存配置 不推荐 建议自定义 ############# spring.cache.cache-namesUSER,ADVERT spring.cache.caffeine.specinitialCapacity50,maximumSize500,expireAfterWrite30s,refreshAfterWrite7s spring.cache.typecaffeine 2、自定义配置 /*** p 缓存名分类 /p*/ public enum CacheNameEnum {/*** 用户*/USER(5, 20L, 60L),/*** 推荐*/ADVERT(5, 10L, 120L);private final Integer initialCapacity;private final Long maximumSize;private final Long expire;CacheNameEnum(Integer initialCapacity, Long maximumSize, Long expire) {this.initialCapacity initialCapacity;this.maximumSize maximumSize;this.expire expire;}public Long getMaximumSize() {return maximumSize;}public Integer getInitialCapacity() {return initialCapacity;}public Long getExpire() {return expire;} } import com.coocaa.system.enums.CacheNameEnum; import com.github.benmanes.caffeine.cache.Caffeine; import org.springframework.cache.CacheManager; import org.springframework.cache.caffeine.CaffeineCache; import org.springframework.cache.support.SimpleCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;import java.time.Duration; import java.util.ArrayList; import java.util.List;/*** author songjianyong* p 本地缓存配置 /p*/ Configuration public class CaffeineCacheConfig {private static final SimpleCacheManager SIMPLE_CACHE_MANAGER new SimpleCacheManager();Beanpublic CacheManager caffeineCacheManager() {ListCaffeineCache caches new ArrayList();for (CacheNameEnum value : CacheNameEnum.values()) {com.github.benmanes.caffeine.cache.CacheObject, Object cache Caffeine.newBuilder().initialCapacity(value.getInitialCapacity()).maximumSize(value.getMaximumSize())//写入后失效时间.expireAfterWrite(Duration.ofSeconds(value.getExpire())).build();caches.add(new CaffeineCache(value.name(), cache));}SIMPLE_CACHE_MANAGER.setCaches(caches);return SIMPLE_CACHE_MANAGER;}} 四、使用注解 org.springframework.cache.annotation.Cacheable(value USER, key#p0.id) 五、进阶处理 自定义 CaffeineCacheManager import com.coocaa.ops.admin.common.enums.CacheNameEnum; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.Caffeine; import org.springframework.beans.factory.InitializingBean; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Configuration; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable;import java.util.HashMap; import java.util.Map;/*** 自定义 CaffeineCacheManager** author songjianyong*/ Configuration public class SongCaffeineCacheManager extends CaffeineCacheManager implements InitializingBean {private final MapString, CaffeineObject, Object builders new HashMap();Nullableprivate CacheLoaderObject, Object cacheLoader;Overridepublic void afterPropertiesSet() throws Exception {for (CacheNameEnum value : CacheNameEnum.values()) {builders.put(value.getCacheName(), Caffeine.from(value.getSpec()));}}OverrideNonNullprotected CacheObject, Object createNativeCaffeineCache(NonNull String name) {CaffeineObject, Object builder builders.get(name);if (builder null) {return super.createNativeCaffeineCache(name);}if (this.cacheLoader ! null) {return builder.build(this.cacheLoader);} else {return builder.build();}}Overridepublic void setCacheLoader(NonNull CacheLoaderObject, Object cacheLoader) {super.setCacheLoader(cacheLoader);this.cacheLoader cacheLoader;} } 辅助代码 /*** 缓存名称枚举** author songjianyong*/ public enum CacheNameEnum {/*** 接口响应结果缓存名称*/SONG_API_RESPONSE(SONG:API:RESPONSE, initialCapacity5,maximumSize50,expireAfterWrite1d),JIAN_API_RESPONSE(JIAN:API:RESPONSE, initialCapacity10,maximumSize100,expireAfterWrite15d);/*** 缓存名称*/private final String cacheName;/*** spec*/private final String spec;CacheNameEnum(String cacheName, String spec) {this.cacheName cacheName;this.spec spec;}public String getCacheName() {return cacheName;}public String getSpec() {return spec;} } 补充下注解 Cacheable表示该方法支持缓存。当调用被注解的方法时如果对应的键已经存在缓存则不再执行方法体而从缓存中直接返回。当方法返回null时将不进行缓存操作。CachePut表示执行该方法后其值将作为最新结果更新到缓存中每次都会执行该方法。CacheEvict表示执行该方法后将触发缓存清除操作。Caching用于组合前三个注解例如 Caching(cacheable Cacheable(CacheConstants.GET_USER),evict {CacheEvict(CacheConstants.GET_DYNAMIC,allEntries true)} public User find(Integer id) {return null; } cacheNames/value缓存组件的名字即cacheManager中缓存的名称。key缓存数据时使用的key。默认使用方法参数值也可以使用SpEL表达式进行编写。keyGenerator和key二选一使用。cacheManager指定使用的缓存管理器。condition在方法执行开始前检查在符合condition的情况下进行缓存unless在方法执行完成后检查在符合unless的情况下不进行缓存sync是否使用同步模式。若使用同步模式在多个线程同时对一个key进行load时其他线程将被阻塞。
http://www.pierceye.com/news/393111/

相关文章:

  • 网站上的网站地图怎么做中国建设银行官网开户行查询
  • 大学网站建设wordpress函数调用
  • 如何上传自己做的网站wordpress the content
  • 公司网站介绍范文dede手机网站标签
  • 彩票网站什么做公司内部网络怎么建立
  • 江苏网站备案要多久wordpress素材模板怎么用
  • 淄博网站建设有实力wordpress 异常
  • 卖汽车的网站怎么做百度图片点击变网站是怎么做的
  • 可以做英文教师的网站桂阳网站建设
  • 常州网站建设外包WordPress cos媒体库
  • 教着做美食的网站wordpress 无法安装主题
  • 只选设计师的网站牛商网是干什么的
  • 网站设计中新闻版块怎么做乐清新闻联播
  • 网站开发维护员挣钱吗全球电子商务公司排行
  • 祥云县住房和城乡建设网站百度热议排名软件
  • 网站开发攻克时间网站模版制作教程
  • 遵义一般做一个网站需要多少钱菲斯曼售后服务中心
  • 教务系统网站建设模板下载东莞企业高端网站建设
  • 淮南建设公司网站网站建设对教育解决方案
  • 泰兴建设局网站wordpress资料图片不显示
  • 外贸推广免费网站图片 网站源码
  • 博客推广那个网站列好邢台网红桥
  • 艺之都网站建设微信app开发腾讯视频分享到wordpress
  • 洛阳最好的做网站的公司哪家好建网站需要哪些文件夹
  • 舟山企业网站建设导出wordpress用户
  • 肇庆新农村建设内容在哪个网站有关天猫网站开发的论文
  • 网站建设代码生成器php网站开发专员招聘
  • 视频教学网站cms陕西网站备案查询
  • 湖州网站设计浙北数据wordpress自定义搜索页面
  • 昆明公司网站开发流线型的网站建设