Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 使用原始数据库文件定期更新iplookUp缓存_Scala_Maxmind - Fatal编程技术网

Scala 使用原始数据库文件定期更新iplookUp缓存

Scala 使用原始数据库文件定期更新iplookUp缓存,scala,maxmind,Scala,Maxmind,我想从maxmind数据库文件GeoIP-City.mmdb为IPLookup创建缓存。 问题是,如果我的应用程序正在运行,并且原始数据库从maxmind更新,那么我的代码将如何在不重新启动的情况下获得更新的文件内容 从maxmind文件读取数据的代码是 val ipLooksUps: IO[IpLookups[IO]] = IpLookups.createFromFilenames( Some(geoFilePath), None, None, None,

我想从maxmind数据库文件GeoIP-City.mmdb为IPLookup创建缓存。 问题是,如果我的应用程序正在运行,并且原始数据库从maxmind更新,那么我的代码将如何在不重新启动的情况下获得更新的文件内容

从maxmind文件读取数据的代码是

val ipLooksUps: IO[IpLookups[IO]] = IpLookups.createFromFilenames(
    Some(geoFilePath),
    None,
    None,
    None,
    false,
    20000
  )

现在ipLookups有了ip地址和城市映射的数据。如何在我的应用程序运行时自动更新它

您可以使用fs2 cron库


您是否手动部署应用程序?
case class Look() {
    val ipLooksUps: IO[IpLookups[IO]] = IpLookups.createFromFilenames(
    Some(geoFilePath),
    None,
    None,
    None,
    false,
    20000)
}

import cats.effect.{IO, Timer}
import cron4s.Cron
import eu.timepit.fs2cron.awakeEveryCron
import fs2.Stream
import scala.concurrent.ExecutionContext

implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)


val cron      = Cron.unsafeParse("*/2 * * ? * *")
val scheduled = awakeEveryCron[IO](cron) >> Stream.eval(IO(Look()))
scheduled.compile.drain.unsafeRunAsyncAndForget()