Created
August 18, 2022 05:09
-
-
Save stella6767/564688d1119bf43ce01510fe178c436e to your computer and use it in GitHub Desktop.
expiringmap을 활용한 인메모리 저장소
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
@Repository | |
class MemoryTokenRepositoryImpl : TokenRepository { | |
/** | |
* https://hippolab.tistory.com/44 | |
* concurrent 지원 | |
* refresh token 저장용 | |
*/ | |
private val log = KotlinLogging.logger { } | |
private val store: MutableMap<String, String> = ExpiringMap.builder() | |
.expiration(JwtManager.refreshTokenExpireDay, TimeUnit.DAYS) | |
.expirationPolicy(ExpirationPolicy.CREATED) | |
//.variableExpiration() | |
.expirationListener(tokenExpiredListen()) | |
.maxSize(10000000) | |
.build() | |
//private val store: MutableMap<String, String> = ConcurrentHashMap() | |
init { | |
//store.removeExpirationListener() | |
} | |
private fun tokenExpiredListen() = { key: String, value: String -> log.info { "key: $key value: $value expired" } } | |
override fun save(key: String, value: String): String { | |
//Thread.sleep(100) | |
store.put(key, value) | |
return value | |
} | |
override fun findByKey(key:String): Optional<String> { | |
return Optional.ofNullable(store[key]) | |
} | |
override fun findAll(): List<String> { | |
return ArrayList<String>(store.values) | |
} | |
override fun remove(key: String): String? { | |
return store.remove(key) | |
} | |
override fun clearStore() { | |
//store.clear() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment