Skip to content

Commit

Permalink
Cleanup README.md format and CHANGLOG.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Jul 23, 2021
1 parent d7f5d96 commit ea91a91
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[*]
insert_final_newline = true
indent_style = space
indent_size = 4

[*.yml]
indent_size = 2

[*.kts]
max_line_length = 200

[*.md]
max_line_length = 200

[*.kt]
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Change Log

## 0.2.0
## Unreleased

### Changed

- `fun newBuilder` to `operator fun invoke`
- Change `fun newBuilder()` to `operator fun invoke()` - [#7](https://github.com/ReactiveCircus/cache4k/pull/7).
- Compile with Kotlin 1.5.21.

## 0.2.0

### Changed

Expand Down
38 changes: 12 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ In-memory Cache for Kotlin Multiplatform.

**Work in progress.**

**cache4k** provides a simple in-memory key-value cache for **Kotlin Multiplatform**, with support
for time-based (expiration) and size-based evictions.
**cache4k** provides a simple in-memory key-value cache for **Kotlin Multiplatform**, with support for time-based (expiration) and size-based evictions.

The following targets are currently supported:

Expand All @@ -25,8 +24,7 @@ The following targets are currently supported:

## Download

Dependencies are hosted
on [Maven Central](https://search.maven.org/artifact/io.github.reactivecircus.cache4k/cache4k).
Dependencies are hosted on [Maven Central](https://search.maven.org/artifact/io.github.reactivecircus.cache4k/cache4k).

### Android

Expand Down Expand Up @@ -85,9 +83,7 @@ cache.get(1) // returns "bird"

### Cache loader

**Cache** provides an API for getting cached value by key and using the
provided `loader: suspend () -> Value` lambda to compute and cache the value automatically if none
exists.
**Cache** provides an API for getting cached value by key and using the provided `loader: suspend () -> Value` lambda to compute and cache the value automatically if none exists.

```kotlin
runBlockingTest {
Expand All @@ -107,8 +103,7 @@ Any exceptions thrown by the `loader` will be propagated to the caller of this f

### Expirations and evictions

By default, **Cache** has an unlimited number of entries which never expire. But a cache can be
configured to support both **time-based expirations** and **size-based evictions**.
By default, **Cache** has an unlimited number of entries which never expire. But a cache can be configured to support both **time-based expirations** and **size-based evictions**.

#### Time-based expiration

Expand All @@ -126,26 +121,22 @@ val cache = Cache.Builder()
.build<Long, String>()
```

An entry in this cache will be removed if it has not been read or replaced **after 24 hours** since
it's been written into the cache.
An entry in this cache will be removed if it has not been read or replaced **after 24 hours** since it's been written into the cache.

##### Expire after write

To set the maximum time an entry can live in the cache since the last write (also known as **
time-to-live**), where "write" means **adding a new cache entry** or **replacing an existing entry
with a new one**:
time-to-live**), where "write" means **adding a new cache entry** or **replacing an existing entry with a new one**:

```kotlin
val cache = Cache.Builder()
.expireAfterWrite(30.minutes)
.build<Long, String>()
```

An entry in this cache will be removed if it has not been replaced **after 30 minutes** since it's
been written into the cache.
An entry in this cache will be removed if it has not been replaced **after 30 minutes** since it's been written into the cache.

_Note that cache entries are **not** removed immediately upon expiration at exact time. Expirations
are checked in each interaction with the `cache`._
_Note that cache entries are **not** removed immediately upon expiration at exact time. Expirations are checked in each interaction with the `cache`._

### Size-based eviction

Expand All @@ -157,8 +148,7 @@ val cache = Cache.Builder()
.build<Long, String>()
```

Once there are more than **100** entries in this cache, the **least recently used one** will be
removed, where "used" means **reading the cache**, **adding a new cache entry**, or **replacing an
Once there are more than **100** entries in this cache, the **least recently used one** will be removed, where "used" means **reading the cache**, **adding a new cache entry**, or **replacing an
existing entry with a new one**.

### Getting all cache entries as a Map
Expand Down Expand Up @@ -231,14 +221,10 @@ fun cacheEntryEvictedAfterExpiration() {

## Credits

The library was ported from a kotlin / JVM cache which I contributed
to [dropbox/Store](https://github.com/dropbox/Store) to help unblock Store's multiplatform support (
it was reverted before the 1.0 release as multiplatform wasn't a priority). Many thanks to Store's
owners and contributors for reviewing and improving the original implementation.
The library was ported from a kotlin / JVM cache which I contributed to [dropbox/Store](https://github.com/dropbox/Store) to help unblock Store's multiplatform support (
it was reverted before the 1.0 release as multiplatform wasn't a priority). Many thanks to Store's owners and contributors for reviewing and improving the original implementation.

Native concurrency support of the library is powered
by [touchlab/Stately](https://github.com/touchlab/Stately). Many thanks to Stately's authors and
contributors for the great library.
Native concurrency support of the library is powered by [touchlab/Stately](https://github.com/touchlab/Stately). Many thanks to Stately's authors and contributors for the great library.

## License

Expand Down

0 comments on commit ea91a91

Please sign in to comment.