https://github.com/rtmigo/jaseca_kt
Easy to use file cache for Kotlin/JVM. Serializes Java classes and stores the data in a directory on a local drive.
https://github.com/rtmigo/jaseca_kt
cache caching directory ehcache file filesystem hdd java jvm kotlin local persistence persistent
Last synced: 1 day ago
JSON representation
Easy to use file cache for Kotlin/JVM. Serializes Java classes and stores the data in a directory on a local drive.
- Host: GitHub
- URL: https://github.com/rtmigo/jaseca_kt
- Owner: rtmigo
- License: apache-2.0
- Created: 2022-09-28T17:18:17.000Z (over 2 years ago)
- Default Branch: staging
- Last Pushed: 2022-10-22T07:41:15.000Z (over 2 years ago)
- Last Synced: 2025-01-21T15:32:16.741Z (5 months ago)
- Topics: cache, caching, directory, ehcache, file, filesystem, hdd, java, jvm, kotlin, local, persistence, persistent
- Language: Kotlin
- Homepage:
- Size: 107 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [jaseca](https://github.com/rtmigo/jaseca_kt)
Easy to use file cache for Kotlin/JVM.
Stores data in a directory on a local drive. Allows you to keep data of any types that are
`java.io.Serializable`.```kotlin
import io.github.rtmigo.jaseca.filecache
import java.nio.file.Pathsfun main() {
filecache(Paths.get("/path/to/cache_dir"))
.use { cache ->
// writing to cache
cache["first key"] = 10
cache["second key"] = 20
// reading from cache
println(cache["first key"])
}
}
```"Jaseca" stands for **JA**va.io.**SE**rializable **CA**che.
In fact, this is a thin wrapper around [Ehcache](https://www.ehcache.org/).
# Install
#### settings.gradle.kts
```kotlin
sourceControl {
gitRepository(java.net.URI("https://github.com/rtmigo/jaseca_kt.git")) {
producesModule("io.github.rtmigo:jaseca")
}
}
```#### build.gradle.kts
```kotlin
dependencies {
implementation("io.github.rtmigo:jaseca") {
version { branch = "staging" }
}
}
```# Use
### Configure, write, read
```kotlin
import io.github.rtmigo.jaseca.filecache
import java.nio.file.Paths
import kotlin.time.Duration.Companion.minutesfun main() {
filecache(Paths.get("/path/to/cache_dir")) {
// optional configuration block
maxEntries = 1000
timeToIdle = 15.minutes
}
.use { cache ->
// writing to cache
cache["first key"] = 10
cache["second key"] = 20
// reading from cache
println(cache["first key"])
}
}
```:warning: You should always use the cache inside `use { }` block or call `.close()`
after use. Otherwise, the data may not be saved to disk.### Save structured data
Just inherit your Kotlin class from `java.io.Serializable` to make it compatible.
```kotlin
import io.github.rtmigo.jaseca.filecache
import java.nio.file.Pathsdata class Planet(val radius: Double, val period: Double)
: java.io.Serializable // this makes the object compatiblefun main() {
filecache(Paths.get("/path/to/cache_dir"))
.use { cache ->
cache["Mars"] = Planet(389.5, 686.980)
cache["Mercury"] = Planet(2439.7, 87.9691)
}
}
```## License
Copyright © 2022 [Artyom IG](https://github.com/rtmigo).
Released under the [Apache-2.0](LICENSE).