Skip to content

Commit 997291a

Browse files
authored
chore(readme): add maven artifacts and instructions
Signed-off-by: iProdigy <[email protected]>
1 parent a748ee1 commit 997291a

File tree

1 file changed

+75
-27
lines changed

1 file changed

+75
-27
lines changed

README.md

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<img src=".github/logo.png?raw=true" alt="Xanthic logo" width="500" />
22

3+
[![Latest](https://img.shields.io/github/release/Xanthic/cache-api/all.svg?style=flate&label=latest)](https://search.maven.org/search?q=g:io.github.xanthic.cache)
4+
[![Build](https://github.com/Xanthic/cache-api/actions/workflows/gradle.yml/badge.svg)](https://github.com/Xanthic/cache-api/actions/workflows/gradle.yml)
5+
[![Javadoc](https://javadoc.io/badge2/io.github.xanthic.cache/cache-api/javadoc.svg)](https://javadoc.io/doc/io.github.xanthic.cache)
6+
37
[![Code Quality](https://www.codefactor.io/repository/github/xanthic/cache-api/badge)](https://www.codefactor.io/repository/github/xanthic/cache-api)
48
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Xanthic_cache-api&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Xanthic_cache-api)
59
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Xanthic_cache-api&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=Xanthic_cache-api)
@@ -29,20 +33,74 @@ example), so it is safer to code against this API for long-term flexibility*
2933

3034
The following backing cache implementations have bindings already provided by this library:
3135

32-
* [Caffeine](https://github.com/ben-manes/caffeine/wiki) via `CaffeineProvider` or `Caffeine3Provider`
33-
* [Guava](https://github.com/google/guava/wiki/CachesExplained) via `GuavaProvider`
34-
* [Cache2k](https://cache2k.org) via `Cache2kProvider`
35-
* [AndroidX](https://developer.android.com/reference/androidx/collection/LruCache) via `AndroidLruProvider`
36-
* [ExpiringMap](https://github.com/jhalterman/expiringmap#expiringmap) via `ExpiringMapProvider`
37-
* [Ehcache v3 (heap)](https://www.ehcache.org/documentation/3.0/index.html) via `EhcacheProvider`
38-
* [Infinispan (heap)](https://infinispan.org/documentation/) via `InfinispanProvider`
36+
| Backend | Provider | Artifact |
37+
| :-----: | :------: | :------: |
38+
| [Caffeine](https://github.com/ben-manes/caffeine/wiki) | `CaffeineProvider` | `cache-provider-caffeine` |
39+
| [Caffeine3](https://github.com/ben-manes/caffeine/wiki) | `Caffeine3Provider` | `cache-provider-caffeine3` |
40+
| [Guava](https://github.com/google/guava/wiki/CachesExplained) | `GuavaProvider` | `cache-provider-guava` |
41+
| [Cache2k](https://cache2k.org) | `Cache2kProvider` | `cache-provider-cache2k` |
42+
| [AndroidX](https://developer.android.com/reference/androidx/collection/LruCache) | `AndroidLruProvider` | `cache-provider-androidx` |
43+
| [ExpiringMap](https://github.com/jhalterman/expiringmap#expiringmap) | `ExpiringMapProvider` | `cache-provider-expiringmap` |
44+
| [Ehcache v3 (heap)](https://www.ehcache.org/documentation/3.0/index.html) | `EhcacheProvider` | `cache-provider-ehcache` |
45+
| [Infinispan (heap)](https://infinispan.org/documentation/) | `InfinispanProvider` | `cache-provider-infinispan` |
3946

4047
Don't see your preferred implementation listed above?
4148
Fear not, it is not difficult to create your own binding, and we'd be happy to accept it in a PR!
4249

50+
## Installation
51+
52+
We publish to [Maven Central](https://search.maven.org/search?q=g:io.github.xanthic.cache) and provide a convenient BOM (Build of Materials) to keep dependency versions in sync from the api to the provider.
53+
54+
Library developers only need to depend on the `cache-core` artifact, allowing application developers to specify which [provider](#supported-implementations) to use at runtime.
55+
56+
### Gradle (Kotlin)
57+
58+
```kotlin
59+
repositories {
60+
mavenCentral()
61+
}
62+
63+
dependencies {
64+
api(platform("io.github.xanthic.cache:cache-bom:0.1.0")) // Specify the latest version here
65+
api(group = "io.github.xanthic.cache", name = "cache-core") // For library devs
66+
implementation(group = "io.github.xanthic.cache", name = "cache-provider-caffeine") // For application devs; can select any provider
67+
}
68+
```
69+
70+
### Maven
71+
72+
```xml
73+
<dependencyManagement>
74+
<dependencies>
75+
<dependency>
76+
<groupId>io.github.xanthic.cache</groupId>
77+
<artifactId>cache-bom</artifactId>
78+
<!-- Specify the latest version here -->
79+
<version>0.1.0</version>
80+
<scope>import</scope>
81+
<type>pom</type>
82+
</dependency>
83+
</dependencies>
84+
</dependencyManagement>
85+
86+
<dependencies>
87+
<!-- For library devs -->
88+
<dependency>
89+
<groupId>io.github.xanthic.cache</groupId>
90+
<artifactId>cache-core</artifactId>
91+
</dependency>
92+
93+
<!-- For application devs (can select any provider) -->
94+
<dependency>
95+
<groupId>io.github.xanthic.cache</groupId>
96+
<artifactId>cache-provider-caffeine</artifactId>
97+
</dependency>
98+
</dependencies>
99+
```
100+
43101
## Example Usage
44102

45-
Users should include at least one provider module in the runtime class-path.
103+
Users should include at least one [provider](#supported-implementations) module in the runtime class-path.
46104
Further, they can (optionally) do (but replace `CaffeineProvider` with the desired provider):
47105

48106
```java
@@ -53,32 +111,22 @@ Define a generic cache:
53111

54112
```java
55113
Cache<String, Integer> cache = CacheApi.create(spec -> {
56-
spec.maxSize(2048L); // setting a size constraint is highly recommended
57-
spec.expiryTime(Duration.ofMinutes(5L));
58-
spec.expiryType(ExpiryType.POST_ACCESS);
59-
spec.removalListener((key, value, cause) -> {
60-
if (cause.isEviction()) {
61-
// do something
62-
}
63-
});
114+
spec.maxSize(2048L); // setting a size constraint is highly recommended
115+
spec.expiryTime(Duration.ofMinutes(5L));
116+
spec.expiryType(ExpiryType.POST_ACCESS);
117+
spec.removalListener((key, value, cause) -> {
118+
if (cause.isEviction()) {
119+
// do something
120+
}
121+
});
64122
});
65123
```
66124

67125
Here, the default provider will be used as `CacheBuilder#provider(CacheProvider)` was not called (note: this builder option is meant for end users rather than library devs).
68126

69127
Aside: the `removalListener` in the example above technically has no effect, but is included for illustration.
70128

71-
Note: Kotlin users can enjoy an [even cleaner](kotlin/src/test/kotlin/io/github/xanthic/cache/ktx/KotlinTest.kt) syntax via the extensions module!
72-
73-
## WIP
74-
75-
This API is still in alpha development stage. The current TODO list includes:
76-
77-
- [x] Add Javadocs
78-
- [x] Incorporate logging (via SLF4J)
79-
- [x] Create test suite (via JUnit)
80-
- [ ] Consider if any more bindings should be added for initial release
81-
- [ ] Eventually: Publish to Maven
129+
Note: Kotlin users can enjoy an [even cleaner](kotlin/src/test/kotlin/io/github/xanthic/cache/ktx/KotlinTest.kt) syntax via the [extensions module](https://search.maven.org/search?q=g:io.github.xanthic.cache%20a:cache-kotlin)!
82130

83131
## FAQ
84132

0 commit comments

Comments
 (0)