Skip to content

Commit 260cfd2

Browse files
authored
Merge pull request #34 from mori-atsushi/v0.0.3
Prepar for v0.0.3
2 parents 8054099 + 2a0e393 commit 260cfd2

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

README.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Enable the Gradle plugin for the module where you want to use this library.
2929
// build.gradle.kts
3030
plugins {
3131
kotlin(/* ... */)
32-
id("com.moriatsushi.cacheable") version "0.0.2"
32+
id("com.moriatsushi.cacheable") version "0.0.3"
3333
}
3434
```
3535

@@ -38,11 +38,11 @@ You also need to add the `cacheable-core` dependency to the module.
3838
```kotlin
3939
// build.gradle.kts
4040
dependencies {
41-
implementation("com.moriatsushi.cacheable:cacheable-core:0.0.2")
41+
implementation("com.moriatsushi.cacheable:cacheable-core:0.0.3")
4242
}
4343
```
4444

45-
## Usage
45+
## Basic Usage
4646

4747
You can use `@Cacheable` annotation to cache the result of specified functions.
4848
When you call a function with this annotation, it will return the cached value if the function is
@@ -69,26 +69,32 @@ fun getSomething(key: String): Something =
6969
If you use the cacheable function within a class, the cache is only shared within an instance of the
7070
class.
7171

72-
In addition, if you specify `maxCount` parameter, the number of cached values will be limited to the
73-
specified value.
74-
If the number of cached values exceeds the specified value, the cache with the oldest access time
75-
will be removed.
72+
You can also use `@Cacheable` annotation for a suspend function.
7673

7774
```kotlin
78-
class SomeClass {
79-
@Cacheable(maxCount = 10)
80-
fun getSomething(key: String): Something {
81-
// ...
82-
}
75+
class Repository(private val api: Api) {
76+
@Cacheable
77+
suspend fun getUser(id: String): User =
78+
api.getUser(id)
8379
}
8480
```
8581

86-
You can also use `@Cacheable` annotation for a suspend function.
82+
## APIs
83+
There are 2 parameters you can specify to `@Cacheable` annotation.
84+
85+
* `maxCount`: The maximum number of cached values. If the number of cached values exceeds this
86+
value, the cache with the oldest access time will be removed. If you don't specify this parameter,
87+
the number of cached values will be unlimited.
88+
* `lock`: When this is `true`, the function is guaranteed to be called only once even if the
89+
function is called multiple times with the same arguments at the same time. Otherwise, the
90+
function may be called multiple times with the same arguments at the same time. The default value
91+
is false.
8792

8893
```kotlin
89-
class Repository(private val api: Api) {
90-
@Cacheable(maxCount = 10)
91-
suspend fun getUser(id: String): User =
92-
api.getUser(id)
94+
class SomeClass {
95+
@Cacheable(maxCount = 10, lock = true)
96+
fun getSomething(key: String): Something {
97+
// ...
98+
}
9399
}
94100
```

cacheable-gradle-plugin/src/main/kotlin/com/moriatsushi/cacheable/gradle/plugin/CacheableCompilerPluginSupportPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CacheableCompilerPluginSupportPlugin : KotlinCompilerPluginSupportPlugin {
1717
override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact(
1818
groupId = "com.moriatsushi.cacheable",
1919
artifactId = "cacheable-compiler",
20-
version = "0.0.2",
20+
version = "0.0.3",
2121
)
2222

2323
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ kotlin.mpp.androidSourceSetLayoutVersion=2
1010
SONATYPE_HOST=S01
1111
RELEASE_SIGNING_ENABLED=false
1212
GROUP=com.moriatsushi.cacheable
13-
VERSION_NAME=0.0.2
13+
VERSION_NAME=0.0.3
1414

1515
POM_NAME=Kotlin Cacheable
1616
POM_DESCRIPTION=An annotation-based cache library for Kotlin Multiplatform.

test/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
22

33
plugins {
44
alias(libs.plugins.kotlin.multiplatform)
5-
id("com.moriatsushi.cacheable") version "0.0.2"
5+
id("com.moriatsushi.cacheable") version "0.0.3"
66
}
77

88
kotlin {

0 commit comments

Comments
 (0)