refactor/Get rid of macmemo 0.6-OBP-SNAPSHOT library

This commit is contained in:
Marko Milić 2024-10-16 10:47:42 +02:00
parent 68f98f4a01
commit 34fa53c085
2 changed files with 0 additions and 48 deletions

View File

@ -443,13 +443,6 @@
<version>3.2.7-RELEASE</version>
</dependency>
<!--macro cache-->
<dependency>
<groupId>com.github.OpenBankProject</groupId>
<artifactId>macmemo</artifactId>
<version>0.6-OBP-SNAPSHOT</version>
</dependency>
<!-- util convert Future to js Promise
<dependency>
<groupId>org.scala-js</groupId>

View File

@ -3,14 +3,11 @@ package code.api.cache
import code.api.Constant._
import code.api.JedisMethod
import code.api.cache.Redis.use
import code.api.util.APIUtil
import code.util.Helper.MdcLoggable
import com.softwaremill.macmemo.{Cache, MemoCacheBuilder, MemoizeParams}
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scala.language.postfixOps
import scala.reflect.runtime.universe._
object Caching extends MdcLoggable {
def memoizeSyncWithProvider[A](cacheKey: Option[String])(ttl: Duration)(f: => A)(implicit m: Manifest[A]): A = {
@ -37,44 +34,6 @@ object Caching extends MdcLoggable {
}
/**
* the default MemoCacheBuilder for annotation OBPMemoize
*
* e.g:
*{{{
* import Caching._
*
* @OBPMemoize(ttl = 2 hours, maxSize = 111)
* def hello(name: String, age: Int): Future[String] = ???
*}}}
*/
implicit object OBPCacheBuilder extends MemoCacheBuilder {
override def build[V : TypeTag : Manifest](bucketId: String, params: MemoizeParams): Cache[V] = new Cache[V] {
val ttl = params.expiresAfterMillis
var isFuture = implicitly[TypeTag[V]].tpe <:< typeOf[Future[_]]
var fixedReturnType = false
override def get(key: List[Any], compute: => V): V = {
val cacheKey = bucketId + "_" + key.mkString("_")
if(isFuture) {
val result = memoizeWithProvider(Some(cacheKey))(ttl)(compute.asInstanceOf[Future[Any]])
result.asInstanceOf[V]
} else if(implicitly[TypeTag[V]].tpe =:= typeOf[Any] && !fixedReturnType) {
val result = compute
isFuture = result.isInstanceOf[Future[_]]
fixedReturnType = true
this.get(key, result)
} else {
val result = memoizeSyncWithProvider(Some(cacheKey))(ttl)(compute)
if(result.isInstanceOf[Future[_]]) {
isFuture = true
}
result
}
}
}
}
def getLocalisedResourceDocCache(key: String) = {
use(JedisMethod.GET, (LOCALISED_RESOURCE_DOC_PREFIX + key).intern(), Some(CREATE_LOCALISED_RESOURCE_DOC_JSON_TTL))
}