You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/01/08 15:15:47 UTC

[GitHub] markusthoemmes closed pull request #3146: Use cache invalidation policy based on access time

markusthoemmes closed pull request #3146: Use cache invalidation policy based on access time
URL: https://github.com/apache/incubator-openwhisk/pull/3146
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala b/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala
index 6fa76d22c5..58663550fa 100644
--- a/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala
+++ b/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala
@@ -91,12 +91,18 @@ private object MultipleReadersSingleWriterCache {
 
 trait CacheChangeNotification extends (CacheKey => Future[Unit])
 
+sealed trait EvictionPolicy
+
+case object AccessTime extends EvictionPolicy
+case object WriteTime extends EvictionPolicy
+
 trait MultipleReadersSingleWriterCache[W, Winfo] {
   import MultipleReadersSingleWriterCache._
   import MultipleReadersSingleWriterCache.State._
 
   /** Subclasses: Toggle this to enable/disable caching for your entity type. */
   protected val cacheEnabled = true
+  protected val evictionPolicy: EvictionPolicy = AccessTime
 
   private object Entry {
     def apply(transid: TransactionId, state: State, value: Option[Future[W]]): Entry = {
@@ -438,14 +444,27 @@ trait MultipleReadersSingleWriterCache[W, Winfo] {
   }
 
   /** This is the backing store. */
-  private val cache: ConcurrentMapBackedCache[Entry] = new ConcurrentMapBackedCache(
-    Caffeine
-      .newBuilder()
-      .asInstanceOf[Caffeine[Any, Future[Entry]]]
-      .expireAfterWrite(5, TimeUnit.MINUTES)
-      .softValues()
-      .build()
-      .asMap())
+  private lazy val cache: ConcurrentMapBackedCache[Entry] = evictionPolicy match {
+    case AccessTime =>
+      new ConcurrentMapBackedCache(
+        Caffeine
+          .newBuilder()
+          .asInstanceOf[Caffeine[Any, Future[Entry]]]
+          .expireAfterAccess(5, TimeUnit.MINUTES)
+          .softValues()
+          .build()
+          .asMap())
+
+    case _ =>
+      new ConcurrentMapBackedCache(
+        Caffeine
+          .newBuilder()
+          .asInstanceOf[Caffeine[Any, Future[Entry]]]
+          .expireAfterWrite(5, TimeUnit.MINUTES)
+          .softValues()
+          .build()
+          .asMap())
+  }
 }
 
 /**
diff --git a/common/scala/src/main/scala/whisk/core/entity/Identity.scala b/common/scala/src/main/scala/whisk/core/entity/Identity.scala
index 358b60f1b4..e1b2526dad 100644
--- a/common/scala/src/main/scala/whisk/core/entity/Identity.scala
+++ b/common/scala/src/main/scala/whisk/core/entity/Identity.scala
@@ -27,6 +27,7 @@ import whisk.common.TransactionId
 import whisk.core.database.MultipleReadersSingleWriterCache
 import whisk.core.database.NoDocumentException
 import whisk.core.database.StaleParameter
+import whisk.core.database.WriteTime
 import whisk.core.entitlement.Privilege
 
 case class UserLimits(invocationsPerMinute: Option[Int] = None,
@@ -50,6 +51,8 @@ object Identity extends MultipleReadersSingleWriterCache[Identity, DocInfo] with
   private val viewName = "subjects/identities"
 
   override val cacheEnabled = true
+  override val evictionPolicy = WriteTime
+
   implicit val serdes = jsonFormat5(Identity.apply)
 
   /**


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services