Skip to content

Commit

Permalink
Fix cache serialization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Mar 27, 2018
1 parent 43f08e8 commit a74cc74
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions spark/src/main/scala/geotrellis/spark/io/AttributeCaching.scala
Expand Up @@ -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)
Expand Down Expand Up @@ -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.