Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mechanism to decorate GraphSail's DataStore #522

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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