让我自己陷入困境。我试图将来自MySQL数据库的数据存储在memcached中5分钟,以降低对数据库的调用。我试图将数据存储在列表中的memcached中,用于不同的案例类。这些是我的案例类别;
case class Provider(id:Int, name:String, region:String, auth_url:String, tenant:String, user:String, pass:String)
case class Plan(id:Int, name:String, price:Int, currency:String, flavor_ref:String, provider:Provider,
cpus:Int, memory:Int, bandwidth:Int, disk:Int, priv_ips:Int, pub_ips:Int)
case class ServerGroup(id:Int, group_name:String, min_servers:Int, max_servers:Int, group_conf_id:String, plan:Plan, cloud:Provider)
case class Server(id:Int, ip:String, owner:String, config_id:String, root_user:String, root_pass:String, chefRun:Date, group:ServerGroup, plan:Plan, cloud:Provider)
以下是我试图将其存储在memcached中的示例
def getProvidersCache: List[Provider] = {
val memcached = Memcached(Configuration("10.16.32.2:11211"), ec)
memcached.awaitGet[List[Provider]]("pol_celestia_providers") match {
case Some(providers) => return providers
case None => {
val providers = getProviders
memcached.awaitSet("pol_celestia_providers", providers, Duration.create(300, "seconds"))
return providers
}
}
}
getProviders
是一个从数据库中检索数据并返回List[Providers]
但是当我编译时,我不断收到这些错误
欢迎任何帮助。
谢谢,利亚姆。
答案 0 :(得分:0)
我已经解决了这个问题,我对这个主题进行了更多的研究,发现了scala / pickling,我现在使用scala / pickling将Lists转换为json并将它们存储在memcached中
e.g。
def getProvidersCache: List[Provider] = {
val memcached = Memcached(Configuration("10.16.32.2:11211"), ec)
memcached.awaitGet[String]("pol_celestia_providers") match {
case Some(data:String) => return (new JSONPickle(data)).unpickle[List[Provider]]
case None => {
val providers = getProviders
memcached.awaitSet("pol_celestia_providers", providers.pickle.value, Duration.create(300, "seconds"))
return providers
}
}
}