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
class UserInfoRepository( | |
private val userInfoLocalDataSource: LocalDataSource<String, UserInfoDataModel>, | |
private val userInfoRemoteDataSource: RemoteDataSource<UserInfoDataModel> | |
) : CachePolicyRepository<UserInfoDataModel>( | |
localDataSource = userInfoLocalDataSource, | |
remoteDataSource = userInfoRemoteDataSource | |
) { | |
suspend fun get(key:String, cachePolicy: CachePolicy): UserInfoDomainModel { | |
val userInfo:UserInfo? = cacheFetch(key, cachePolicy) | |
// Do your mapping, etc. and return domain model |
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
package com.example.android.repositories.cache | |
import com.example.android.repositories.cache.CachePolicy.Type.NEVER | |
import com.example.android.repositories.cache.CachePolicy.Type.CLEAR | |
import com.example.android.repositories.cache.CachePolicy.Type.ALWAYS | |
import com.example.android.repositories.cache.CachePolicy.Type.EXPIRES | |
import com.example.android.repositories.cache.CachePolicy.Type.REFRESH | |
abstract class CachePolicyRepository<T>( | |
private val localDataSource: LocalDataSource<String, CacheEntry<T>>, |
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
val userInfo: UserInfoDomainModel = userDataRepository.get( | |
userToken, | |
CachePolicy(CachePolicy.Type.REFRESH) | |
) |
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
val userInfo: UserInfoDomainModel = userDataRepository.get( | |
userToken, | |
CachePolicy(CachePolicy.Type.ALWAYS) | |
) |
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
data class CachePolicy( | |
val type: Type? = Type.ALWAYS, | |
val expires: Long = 0 | |
) { | |
enum class Type { | |
NEVER, // never create a cache line for the key | |
ALWAYS, // always create a cache line for the key | |
REFRESH, // re-fetch (refresh) the cache line for the key | |
CLEAR, // clear the cache line for the key | |
EXPIRES // expire this cache line and refresh if older than expires |
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
#!/bin/sh | |
RESULT="" | |
if [ -p /dev/stdin ]; then | |
while read -ra line ; do | |
if [[ $line[0] == *"[90m/"* ]]; then | |
unset 'line[0]' | |
ROW=$(echo "${line[*]}" | tr "(\n)" " ") | |
RESULT="$RESULT$ROW\n" | |
fi | |
done |
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
apply plugin: "org.jlleitschuh.gradle.ktlint" | |
ktlint { | |
version = "0.34.2" | |
debug = true | |
verbose = true | |
android = false | |
outputToConsole = true | |
reporters = [ReporterType.PLAIN, ReporterType.CHECKSTYLE] | |
ignoreFailures = true |