Skip to content

Instantly share code, notes, and snippets.

View k1dbl4ck's full-sized avatar

Werner Venter k1dbl4ck

  • Takeaway.com
  • Netherlands
View GitHub Profile
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
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>>,
val userInfo: UserInfoDomainModel = userDataRepository.get(
userToken,
CachePolicy(CachePolicy.Type.REFRESH)
)
val userInfo: UserInfoDomainModel = userDataRepository.get(
userToken,
CachePolicy(CachePolicy.Type.ALWAYS)
)
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
#!/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
@k1dbl4ck
k1dbl4ck / ktlint.gradle
Last active April 16, 2020 11:47
ktlint gradle setup
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