Permalink
Browse files

Fix cache serialization issues

  • Loading branch information...
pomadchin committed Mar 27, 2018
1 parent 43f08e8 commit a74cc745a3877640d002f24d4b81bdd6d4d35838
Showing with 10 additions and 7 deletions.
  1. +10 −7 spark/src/main/scala/geotrellis/spark/io/AttributeCaching.scala
@@ -25,18 +25,14 @@ import com.typesafe.config.ConfigFactory
import scala.concurrent.duration._
trait AttributeCaching { self: AttributeStore =>
@transient private lazy val (enabled, cache) = {
val config = ConfigFactory.load()
val expiration = config.getInt("geotrellis.attribute.caching.expirationMinutes")
val maxSize = config.getInt("geotrellis.attribute.caching.maxSize")
val enabled = config.getBoolean("geotrellis.attribute.caching.enabled")
import AttributeCaching._
enabled -> Scaffeine()
@transient private lazy val cache =
Scaffeine()
.recordStats()
.expireAfterWrite(expiration.minutes)
.maximumSize(maxSize)
.build[(LayerId, String), Any]
}
def cacheRead[T: JsonFormat](layerId: LayerId, attributeName: String): T = {
if(enabled)
@@ -65,3 +61,10 @@ trait AttributeCaching { self: AttributeStore =>
if(enabled) cache.invalidate(id -> attribute)
}
}
object AttributeCaching extends Serializable {
lazy val config = ConfigFactory.load()
lazy val expiration = config.getInt("geotrellis.attribute.caching.expirationMinutes")
lazy val maxSize = config.getInt("geotrellis.attribute.caching.maxSize")
lazy val enabled = config.getBoolean("geotrellis.attribute.caching.enabled")
}

0 comments on commit a74cc74

Please sign in to comment.