mirror of
https://github.com/etesync/android
synced 2025-02-08 13:42:43 +00:00
LocalEtebaseCache: make sure we always return the same item.
This commit is contained in:
parent
eeb93f523d
commit
79b650da38
@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import com.etebase.client.*
|
import com.etebase.client.*
|
||||||
import com.etebase.client.Collection
|
import com.etebase.client.Collection
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.HashMap
|
||||||
|
|
||||||
/*
|
/*
|
||||||
File structure:
|
File structure:
|
||||||
@ -83,8 +84,19 @@ class EtebaseLocalCache private constructor(context: Context, username: String)
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private val localCacheCache: HashMap<String, EtebaseLocalCache> = HashMap()
|
||||||
|
|
||||||
fun getInstance(context: Context, username: String): EtebaseLocalCache {
|
fun getInstance(context: Context, username: String): EtebaseLocalCache {
|
||||||
return EtebaseLocalCache(context, username)
|
synchronized(localCacheCache) {
|
||||||
|
val cached = localCacheCache.get(username)
|
||||||
|
if (cached != null) {
|
||||||
|
return cached
|
||||||
|
} else {
|
||||||
|
val ret = EtebaseLocalCache(context, username)
|
||||||
|
localCacheCache.set(username, ret)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEtebase(context: Context, settings: AccountSettings): Account {
|
fun getEtebase(context: Context, settings: AccountSettings): Account {
|
||||||
|
Loading…
Reference in New Issue
Block a user