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

江苏建设工程网站优化推广怎么做

江苏建设工程,网站优化推广怎么做,申远空间设计公司官网,网站建设衤金手指花总十四Caffeine Caffeine是一种基于Java的高性能缓存库,它提供了可配置、快速、灵活的缓存实现。Caffeine具有以下特点: 高性能:Caffeine使用了一些优化技术,如基于链表的并发哈希表和无锁算法,以提供卓越的读写性能。容量…

Caffeine

Caffeine是一种基于Java的高性能缓存库,它提供了可配置、快速、灵活的缓存实现。Caffeine具有以下特点:

  • 高性能:Caffeine使用了一些优化技术,如基于链表的并发哈希表和无锁算法,以提供卓越的读写性能。
  • 容量控制:Caffeine支持多种容量控制策略,如基于大小、基于权重和基于时间等,可以根据需求设置缓存的最大大小或最大权重,并在缓存达到限制时进行逐出策略。
  • 过期策略:Caffeine提供了各种内置的过期策略,如基于访问时间、基于写入时间和定时过期等,在缓存中存储的对象可以根据这些策略进行自动过期。
  • 异步加载:Caffeine支持异步加载数据,当缓存中不存在某个键对应的值时,可以通过自定义的Loader接口来异步加载数据。
  • 统计和监听:Caffeine提供了缓存统计功能,可以获取缓存的命中率、缓存项数量等信息,还支持注册缓存监听器,在缓存发生变化时触发相应的事件。

序列化

Caffeine缓存不涉及任何序列化,因此目标缓存对象不需要实现Serializable接口。若涉及多级缓存或者多种缓存共用,其它需要网络传输或者持久化的缓存需要序列化,Caffeine尽管也使用实现序列化的实体类,但是不做序列化操作。

不需要序列化,降低了缓存使用难度。

引入依赖

<dependency><groupId>com.github.ben-manes.caffeine</groupId><artifactId>caffeine</artifactId>
</dependency>

全局配置

spring:cache:type: caffeine

缓存配置

配置缓存管理器:多CacheName配置。

public interface CacheNameTimeConstant {String CACHE_DEFAULT = "CACHE_DEFAULT";String CACHE_10SECS = "CACHE_10SECS";String CACHE_60SECS = "CACHE_60SECS";
}

同一个CacheManager配置多个CacheName,此处仅配置过期时间的差异,其余配置可自由增加。

import com.example.demo.util.CacheNameTimeConstant;
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.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;@Configuration
public class CaffeineConfig{@Beanpublic CacheManager caffeineCacheManager() {SimpleCacheManager cacheManager = new SimpleCacheManager();List<CaffeineCache> caches = new ArrayList<>();caches.add(new CaffeineCache(CacheNameTimeConstant.CACHE_5SECS,Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build()));caches.add(new CaffeineCache(CacheNameTimeConstant.CACHE_10SECS,Caffeine.newBuilder().expireAfterWrite(10, TimeUnit.SECONDS).build()));caches.add(new CaffeineCache(CacheNameTimeConstant.CACHE_30SECS,Caffeine.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build()));cacheManager.setCaches(caches);return cacheManager;}
}

controller


@RestController
@RequestMapping("/test")
public class TestController {@Resourceprivate StuMapper stuMapper;/*** 添加缓存*/@GetMapping("/selectStu/{id}")@Cacheable(value = CacheNameTimeConstant.CACHE_30SECS,key="#id")public Student selectStu(@PathVariable Integer id){return stuMapper.selectById(id);}/*** 更新缓存*/@PostMapping("/updateStu")@CachePut(value = CacheNameTimeConstant.CACHE_30SECS,key = "#student.id")public Student updateStu(Student student){if (stuMapper.updateById(student) > 0) {return stuMapper.selectById(student.getId());}return  null;}/*** 删除缓存*/@PostMapping("/deleteStu/{id}")@CacheEvict(value = CacheNameTimeConstant.CACHE_30SECS,key = "#id")public String deleteStu(@PathVariable Integer id){return stuMapper.deleteById(id) > 0 ? "删除成功" : "删除失败";}}

启动类

添加@EnableCaching注解

@SpringBootApplication
@EnableTransactionManagement
@EnableCaching
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);System.out.println("启动成功");}@Beanpublic MessageConverter jsonMessageConverter(){return new Jackson2JsonMessageConverter();}}

测试

第一次查询,是走数据库的

第二次查询不走数据库,直接返回缓存,但是30s后过期

 更新缓存

再次查询数据时,从更新的缓存获取

http://www.hkea.cn/news/526091/

相关文章:

  • 沙井营销型网站建设成人培训机构
  • 网站没有被百度收录搜索引擎排名优化公司
  • 手机网站转换小程序晋江怎么交换友情链接
  • 专业做网站的公司疫情放开最新消息今天
  • 不用写代码做网站软件长沙优化网站
  • o2o商城网站建设方案广告策划案优秀案例
  • 日照做网站的那家做的好百度网页链接
  • 建设云个人证件查询系统上海seo培训
  • 网站流量提供商杭州seo排名
  • 做装饰工程的在什么网站投标自建站
  • 地球人--一家只做信誉的网站帮忙推广的平台
  • 网站建设外包协议天津网站排名提升
  • 邯郸教育行业网站建设百度推广代理商查询
  • 政府网站有哪些网站seo最新优化方法
  • 做广告牌子seo外链工具
  • 微信页面设计网站兰州网络推广技术
  • 上门做网站搜狗站长工具
  • wordpress用户邮箱验证码百度seo搜索引擎优化培训
  • 360极速怎么屏蔽网站新闻热点大事件
  • 购物app开发价格表站长工具seo排名
  • 微餐饮网站建设营销型网站建设方案
  • 高端网站建设公司好不好2020国内搜索引擎排行榜
  • 网站建设服务公司选哪家比较好?苏州优化收费
  • 中国建设银行河南省分行网站推广信息哪个平台好
  • 网站建设官网免费模板杭州seo优化
  • 绍兴网站建设谷歌搜索引擎在线
  • 网站的会员认证怎么做黑龙江新闻头条最新消息
  • 做网站如何分工百度推广登录平台客服
  • 网站建设如何提案万网域名注册信息查询
  • 创意二维码制作网站企业网络营销推广案例