
geotrellis.spark.io.AttributeCaching.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geotrellis-spark_2.10 Show documentation
Show all versions of geotrellis-spark_2.10 Show documentation
GeoTrellis is an open source geographic data processing engine for high performance applications.
The newest version!
package geotrellis.spark.io
import geotrellis.spark.LayerId
import spray.json.JsonFormat
trait AttributeCaching { self: AttributeStore =>
private val cache = new collection.mutable.HashMap[(LayerId, String), Any]
def cacheRead[T: JsonFormat](layerId: LayerId, attributeName: String): T = {
cache.getOrElseUpdate(layerId -> attributeName, read[T](layerId, attributeName)).asInstanceOf[T]
}
def cacheWrite[T: JsonFormat](layerId: LayerId, attributeName: String, value: T): Unit = {
cache.update(layerId -> attributeName, value)
write[T](layerId, attributeName, value)
}
def clearCache(): Unit = {
cache.clear()
}
def clearCache(id: LayerId): Unit = {
cache.keySet.filter(_._1 == id).foreach(cache.remove)
}
def clearCache(id: LayerId, attribute: String): Unit = {
cache.remove((id, attribute))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy