微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

cache2k 内存缓存解决方案

程序名称:cache2k

授权协议: GPLv3

操作系统: 跨平台

开发语言: Java

cache2k 介绍

cache2k 是个成熟的性能优越的内存缓存解决方案。

Maven:

<properties>
  <cache2k-version>1.0.2.Final</cache2k-version>
</properties>

<dependencies>
  <dependency>
    <groupId>org.cache2k</groupId>
    <artifactId>cache2k-api</artifactId>
    <version>${cache2k-version}</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>org.cache2k</groupId>
    <artifactId>cache2k-all</artifactId>
    <version>${cache2k-version}</version>
    <scope>runtime</scope>
  </dependency>
</dependencies>

示例代码

Cache<String, String> cache = new Cache2kBuilder<String, String>() {}
  .name("routetoAirline")
  .eternal(true)
  .entryCapacity(100)
  .build();
// populate with our favorites
cache.put("MUC-SFO", "Yeti Jet");
cache.put("SFO-LHR", "Quality Air");
cache.put("LHR-SYD", "Grashopper Lifting");
// query the cache
String route = "LHR-MUC";
if (cache.containsKey(route)) {
  System.out.println("We have a favorite airline for the route " + route);
} else {
  System.out.println("We don't have a favorite airline for the route " + route);
}
String airline = cache.peek(route);
if (airline != null) {
  System.out.println("Let's go with " + airline);
} else {
  System.out.println("You need to find one yourself");
}

cache2k 官网

http://cache2k.org/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐