Skip to content

Conversation

@alexdeleon
Copy link

Hi there,
This minor change allows one to decorate the DataStore of connections to add capabilities (e.g. caching). Here is an example how I use it:

trait CachingGraphSail[T <: KeyIndexableGraph] extends GraphSail[T] {
  import CachingGraphSail._

  override def createStore(): DataStore[T] = new DataStore[T] with CachedDataStore[T]

  trait CachedDataStore[T <: KeyIndexableGraph] extends  DataStore[T] {

    val vertexCache = CacheBuilder.newCache(classOf[Value], classOf[Vertex]).
      maxSize(10000000).
      eternal(true).
      source(super.getVertex _).
      build()

    abstract override def getVertex(value: Value): Vertex = vertexCache.get(value)
  }
}

object CachingGraphSail {
  implicit  def FunctionAsCacheSource[A,B](f: A=>B): CacheSource[A, B] = new CacheSource[A,B] {
    override def get(k: A): B = f(k)
  }
}

Best,
Alex

Review on Reviewable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants