org.scalatra.swagger.reflect.Memo.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalatra-swagger-jakarta_3 Show documentation
Show all versions of scalatra-swagger-jakarta_3 Show documentation
Scalatra integration with Swagger
package org.scalatra.swagger.reflect
import java.util.concurrent.ConcurrentHashMap
private[reflect] class Memo[A, R] {
private[this] val cache = new ConcurrentHashMap[A, R](1500, 1, 1)
def apply(x: A, f: A => R): R = {
if (cache.containsKey(x))
cache.get(x)
else {
val v = f(x)
replace(x, v)
}
}
def replace(x: A, v: R): R = {
cache.put(x, v)
v
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy