zknotify-cache

A ZooKeeper notify reload cache

License

License

The Artistic License 2.0
Categories

Categories

Ant Build Tools
GroupId

GroupId

com.github.phantomthief
ArtifactId

ArtifactId

zknotify-cache
Last Version

Last Version

0.1.22
Release Date

Release Date

Type

Type

jar
Description

Description

zknotify-cache
A ZooKeeper notify reload cache
Project URL

Project URL

https://github.com/PhantomThief/zknotify-cache
Source Code Management

Source Code Management

https://github.com/PhantomThief/zknotify-cache.git

Download zknotify-cache

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.phantomthief/zknotify-cache/ -->
<dependency>
    <groupId>com.github.phantomthief</groupId>
    <artifactId>zknotify-cache</artifactId>
    <version>0.1.22</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.phantomthief/zknotify-cache/
implementation 'com.github.phantomthief:zknotify-cache:0.1.22'
// https://jarcasting.com/artifacts/com.github.phantomthief/zknotify-cache/
implementation ("com.github.phantomthief:zknotify-cache:0.1.22")
'com.github.phantomthief:zknotify-cache:jar:0.1.22'
<dependency org="com.github.phantomthief" name="zknotify-cache" rev="0.1.22">
  <artifact name="zknotify-cache" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.phantomthief', module='zknotify-cache', version='0.1.22')
)
libraryDependencies += "com.github.phantomthief" % "zknotify-cache" % "0.1.22"
[com.github.phantomthief/zknotify-cache "0.1.22"]

Dependencies

compile (5)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.14
com.github.phantomthief : more-lambdas jar 0.1.25
org.apache.curator : curator-recipes jar 4.1.0
com.google.guava : guava jar 28.1-jre
com.google.code.findbugs : jsr305 Optional jar 3.0.2

test (5)

Group / Artifact Type Version
org.apache.curator : curator-test jar 4.1.0
org.junit.jupiter : junit-jupiter-api jar
org.junit.jupiter : junit-jupiter-engine jar
ch.qos.logback : logback-classic jar 1.2.3
org.mockito : mockito-core jar 2.23.4

Project Modules

There are no modules declared in this project.

zknotify-cache

Build Status Coverage Status Total alerts Language grade: Java Maven Central

ZooKeeper通知更新的本地缓存

  • 缓存按需延迟懒加载
  • 通知加载可设置随机延迟,防止所有节点同时加载造成数据源瞬时压力过大
  • 旧的缓存内容可定制清理回调
  • 只支持Java8

Get Started

ReloadableCache<List<String>> cache = ZkNotifyReloadCache.<List<String>> newBuilder()
				.withCacheFactory(this::buildFromSource) // 配置cache构建方法,必须
				.withNotifyZkPath("/notifyPath1") // zk监听变更的路径,必须
				.withCuratorFactory(this::getCuratorFactory) // 提供zkClient的工场方法,必须
				.withMaxRandomSleepOnNotifyReload(30*1000) // zk通知reload时随机最大延迟时间,可选
				.withOldCleanup(this::cleanup) // 旧数据的清理方法,可选
				.enableAutoReload(1, TimeUnit.MINUTES) // 打开自动定时加载,可选
				.build();

List<String> content = cache.get(); // 获取内容,第一次调用本方法时才初始化

cache.reload(); // 通过zk通知所有节点更新
private List<String> buildFromSource() {
	// 从数据源加载数据
}

private CuratorFramework getCuratorFactory() {
	// 返回一个初始化好的CuratorFramework
}

private void cleanup(List<String> list) {
	// 清理旧对象操作
}

Versions

Version
0.1.22
0.1.21
0.1.20
0.1.19
0.1.18
0.1.16
0.1.15
0.1.14
0.1.13
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0