Skip to content
Snippets Groups Projects
Commit 38f6bce3 authored by Matei Zaharia's avatar Matei Zaharia
Browse files

Added SerializingCache

parent 6316c797
No related branches found
No related tags found
No related merge requests found
......@@ -117,7 +117,7 @@ class KryoSerialization extends SerializationStrategy with Logging {
val kryo = new Kryo()
val toRegister: Seq[AnyRef] = Seq(
// Arrays
Array(1), Array(1.0), Array(1.0f), Array(1L), Array(""),
Array(1), Array(1.0), Array(1.0f), Array(1L), Array(""), Array(("", "")),
// Specialized Tuple2s
("", ""), (1, 1), (1.0, 1.0), (1L, 1L),
(1, 1.0), (1.0, 1), (1L, 1.0), (1.0, 1L), (1, 1L), (1L, 1),
......
package spark
import java.io._
/**
* Wrapper around a BoundedMemoryCache that stores serialized objects as
* byte arrays in order to reduce storage cost and GC overhead
*/
class SerializingCache extends Cache with Logging {
val bmc = new BoundedMemoryCache
override def put(key: Any, value: Any) {
val ser = Serializer.newInstance()
bmc.put(key, ser.serialize(value))
}
override def get(key: Any): Any = {
val bytes = bmc.get(key)
if (bytes != null) {
val ser = Serializer.newInstance()
return ser.deserialize(bytes.asInstanceOf[Array[Byte]])
} else {
return null
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment