ctiliescu / scala-cache   0.1

GitHub

A easy to use scala library for allowing you to cache function results using redis.

Scala versions: 2.12

Scala cache library using Redis

Key features of the library


Instalation


The artifacts are published to Maven Central.

libraryDependencies ++= Seq(
  "io.github.ctiliescu" % "scala-cache_2.12" % "0.1",
  ...
)

Usage


To be able to cache the function results, the CacheCompuser should be mixed and defined the RedisConfig properties(address and port).

class Test extends CacheComposer {
  override val conf = RedisConfig("localhost", 6379)

  def func(arg1: String, arg2: String): String = {
    println("Start execute complex function")
    // Very time consuming function
    s"$arg1:$arg2"
  };

  var r1 = cache(func, "v1", "v2")
  pritnln(r1)
  var r2 = cache(func, "v1", "v2")
  pritnln(r2)
  var r3 = cache(func, "v1", "v3")
  pritnln(r3)
  var r4 = cache(func, "v1", "v2")
  pritnln(r4)
}

When the Test class is executed the output will be:

  scala> "execute_test_class"
  Start execute complex function
  v1:v2
  v1:v2
  Start execute complex function
  v1:v3
  v1:v2

Requirements