-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee4cf3f
commit 5cd0cde
Showing
17 changed files
with
176 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
apply from: "${project.rootDir}/gradle/kotlin/processor.gradle" | ||
|
||
group = 'com.kotlitecture.kotli' | ||
version = '0.3.0' | ||
version = '0.4.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...sor/src/main/kotlin/kotli/template/multiplatform/compose/common/CommonStatelyProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kotli.template.multiplatform.compose.common | ||
|
||
import kotli.engine.BaseFeatureProcessor | ||
import kotli.engine.TemplateState | ||
import kotli.engine.template.VersionCatalogRules | ||
import kotli.engine.template.rule.RemoveMarkedLine | ||
|
||
object CommonStatelyProcessor : BaseFeatureProcessor() { | ||
|
||
override fun getId(): String = "common.stately" | ||
override fun isInternal(): Boolean = true | ||
|
||
override fun doRemove(state: TemplateState) { | ||
state.onApplyRules( | ||
VersionCatalogRules( | ||
RemoveMarkedLine("stately") | ||
) | ||
) | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...ssor/src/main/kotlin/kotli/template/multiplatform/compose/dataflow/cache/CacheProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package kotli.template.android.compose.dataflow.cache | ||
package kotli.template.multiplatform.compose.dataflow.cache | ||
|
||
import kotli.engine.FeatureProcessor | ||
import kotli.template.android.compose.dataflow.BaseDataFlowProvider | ||
import kotli.template.android.compose.dataflow.cache.basic.BasicCacheProcessor | ||
import kotli.template.multiplatform.compose.dataflow.BaseDataFlowProvider | ||
import kotli.template.multiplatform.compose.dataflow.cache.basic.BasicCacheProcessor | ||
|
||
class CacheProvider : BaseDataFlowProvider() { | ||
object CacheProvider : BaseDataFlowProvider() { | ||
|
||
override fun getId(): String = "dataflow.cache" | ||
override fun createProcessors(): List<FeatureProcessor> = listOf( | ||
BasicCacheProcessor() | ||
BasicCacheProcessor | ||
) | ||
|
||
} |
45 changes: 38 additions & 7 deletions
45
...n/kotlin/kotli/template/multiplatform/compose/dataflow/cache/basic/BasicCacheProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,53 @@ | ||
package kotli.template.android.compose.dataflow.cache.basic | ||
package kotli.template.multiplatform.compose.dataflow.cache.basic | ||
|
||
import kotli.engine.BaseFeatureProcessor | ||
import kotli.engine.FeatureProcessor | ||
import kotli.engine.TemplateState | ||
import kotli.engine.template.VersionCatalogRules | ||
import kotli.engine.template.rule.CleanupMarkedLine | ||
import kotli.engine.template.rule.RemoveFile | ||
import kotli.engine.template.rule.RemoveMarkedLine | ||
import kotli.template.multiplatform.compose.Rules | ||
import kotli.template.multiplatform.compose.common.CommonStatelyProcessor | ||
import kotli.template.multiplatform.compose.showcases.datasource.cache.CacheShowcasesProcessor | ||
import kotlin.time.Duration.Companion.hours | ||
|
||
class BasicCacheProcessor : BaseFeatureProcessor() { | ||
object BasicCacheProcessor : BaseFeatureProcessor() { | ||
|
||
const val ID = "dataflow.cache.basic" | ||
|
||
override fun getId(): String = ID | ||
override fun getIntegrationEstimate(state: TemplateState): Long = 8.hours.inWholeMilliseconds | ||
override fun dependencies(): List<Class<out FeatureProcessor>> = listOf( | ||
CacheShowcasesProcessor::class.java, | ||
CommonStatelyProcessor::class.java | ||
) | ||
|
||
override fun doRemove(state: TemplateState) { | ||
state.onApplyRules("core/data/src/main/kotlin/core/data/datasource/cache", RemoveFile()) | ||
state.onApplyRules("*CacheSource*", RemoveFile()) | ||
override fun doApply(state: TemplateState) { | ||
state.onApplyRules( | ||
Rules.BuildGradleSharedData, | ||
CleanupMarkedLine("{dataflow.cache.basic}") | ||
) | ||
} | ||
|
||
companion object { | ||
const val ID = "dataflow.cache.basic" | ||
override fun doRemove(state: TemplateState) { | ||
state.onApplyRules( | ||
Rules.CacheSource, | ||
RemoveFile() | ||
) | ||
state.onApplyRules( | ||
Rules.AppDIKt, | ||
RemoveMarkedLine("CacheSource") | ||
) | ||
state.onApplyRules( | ||
Rules.BuildGradleSharedData, | ||
RemoveMarkedLine("{dataflow.cache.basic}") | ||
) | ||
state.onApplyRules( | ||
VersionCatalogRules( | ||
RemoveMarkedLine("stately-concurrent-collections") | ||
) | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...otli/template/multiplatform/compose/showcases/datasource/cache/CacheShowcasesProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package kotli.template.multiplatform.compose.showcases.datasource.cache | ||
|
||
import kotli.engine.BaseFeatureProcessor | ||
import kotli.engine.TemplateState | ||
import kotli.engine.template.rule.RemoveFile | ||
import kotli.engine.template.rule.RemoveMarkedLine | ||
import kotli.template.multiplatform.compose.Rules | ||
|
||
object CacheShowcasesProcessor : BaseFeatureProcessor() { | ||
|
||
const val ID = "showcases.datasource.cache" | ||
|
||
override fun getId(): String = ID | ||
override fun isInternal(): Boolean = true | ||
|
||
override fun doRemove(state: TemplateState) { | ||
state.onApplyRules( | ||
Rules.ShowcasesKt, | ||
RemoveMarkedLine("Cache") | ||
) | ||
state.onApplyRules( | ||
Rules.ShowcasesCacheDir, | ||
RemoveFile() | ||
) | ||
state.onApplyRules( | ||
Rules.AppKt, | ||
RemoveMarkedLine("BasicCacheViewModel") | ||
) | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...ources/kotli/template/multiplatform/compose/dataflow/cache/basic/description.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Thread-safe API for storing and retrieving any in-memory data. Can be utilized as an L1 Cache when managing HTTP requests, offering an efficient means to present data without delays, but with the ability to update based on expiration and other conditions. |
1 change: 1 addition & 0 deletions
1
...in/resources/kotli/template/multiplatform/compose/dataflow/cache/basic/title.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Basic In-Memory Cache API |
53 changes: 53 additions & 0 deletions
53
...in/resources/kotli/template/multiplatform/compose/dataflow/cache/basic/usage.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
## Overview | ||
|
||
The API can be accessed through: | ||
- `shared.data.datasource.cache.CacheSource` - facade interface at the core module level. | ||
- `app.datasource.cache.AppCacheSource` - decorator class at the app level. | ||
|
||
The difference is that the class serves as a **decorator** and can provide extra methods without impacting facade implementations. | ||
|
||
Facade **CacheSource** provides the following methods: | ||
|
||
- `getState(key: CacheKey<T>, valueProvider: suspend () -> T?): CacheState<T>` - Retrieves the state of a cache entry associated with the specified key. | ||
- `get(key: CacheKey<T>, valueProvider: suspend () -> T?): T?` - Retrieves the value associated with the specified key from the cache. | ||
- `invalidate(type: Class<K>)` - Invalidates all cache entries associated with the specified key type. | ||
- `invalidate(key: K)` - Invalidates the cache entry associated with the specified key. | ||
- `remove(type: Class<K>)` - Removes all cache entries associated with the specified key type. | ||
- `remove(key: K)` - Removes the cache entry associated with the specified key. | ||
- `put(key: CacheKey<T>, value: T)` - Associates the specified value with the specified key in the cache. | ||
- `clear()` - Clears all entries from the cache. | ||
|
||
## Example | ||
|
||
Both the **facade** and **decorator** are pre-configured via dependency injection (DI) as singletons in `app.di.datasource.ProvidesCacheSource`. | ||
|
||
To start using, just inject it to your DI managed class. | ||
|
||
```kotlin | ||
class BasicCacheViewModel( | ||
private val cacheSource: CacheSource = get() | ||
) : BaseViewModel() { | ||
|
||
val cacheStore = StoreObject<String>() | ||
|
||
override fun doBind() { | ||
launchAsync { | ||
val cacheKey = SimpleCacheKey() | ||
val cacheState = cacheSource.getState(cacheKey, ::getDateAsFormattedString) | ||
cacheState.changes().collectLatest(cacheStore::set) | ||
} | ||
} | ||
|
||
private fun getDateAsFormattedString(): String { | ||
val time = Clock.System.now() | ||
return time.format(DateTimeComponents.Format { | ||
byUnicodePattern("yyyy-MM-dd HH:mm:ss") | ||
}) | ||
} | ||
|
||
private data class SimpleCacheKey( | ||
override val ttl: Long = CacheKey.TTL_10_SECONDS | ||
) : CacheKey<String> | ||
|
||
} | ||
``` |
1 change: 1 addition & 0 deletions
1
...src/main/resources/kotli/template/multiplatform/compose/dataflow/cache/title.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters